Skip to content

Commit

Permalink
awake and on destroy methods to destroy all avatar components
Browse files Browse the repository at this point in the history
  • Loading branch information
srcnalt committed Sep 18, 2024
1 parent 7babd6f commit 782d711
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion Runtime/Core/Scripts/Data/AvatarData.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
using UnityEngine;
using System;
using UnityEngine;

namespace ReadyPlayerMe.Core
{
public class AvatarData : MonoBehaviour
{
public string AvatarId;
public AvatarMetadata AvatarMetadata;

private SkinnedMeshRenderer[] meshes;

private void Awake()
{
meshes = GetComponentsInChildren<SkinnedMeshRenderer>();
}

private void OnDestroy()
{
foreach (var mesh in meshes)
{
var materials = mesh.sharedMaterials;

foreach (var material in materials)
{
if(material == null) continue;

foreach (var property in material.GetTexturePropertyNames())
{
Texture texture = material.GetTexture(property);

if(texture == null) continue;

Destroy(texture);
}
Destroy(material);
}

Destroy(mesh.sharedMesh);
}
}
}
}

0 comments on commit 782d711

Please sign in to comment.