From 70f3e7a46ba24e4a20d35077a3c4cbd81ddc7257 Mon Sep 17 00:00:00 2001 From: "Sercan (Sarge) Altundas" Date: Wed, 18 Sep 2024 21:04:39 +0300 Subject: [PATCH] Avatar Destroy (#319) ## [TICKETID](https://ready-player-me.atlassian.net/browse/TICKETID) ## Description - Briefly describe what this change will do ## How to Test - Add steps to locally test these changes ## Checklist - [ ] Tests written or updated for the changes. - [ ] Documentation is updated. - [ ] Changelog is updated. --- Runtime/Core/Scripts/Data/AvatarData.cs | 35 ++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Runtime/Core/Scripts/Data/AvatarData.cs b/Runtime/Core/Scripts/Data/AvatarData.cs index 89bc28ae..ad371f9f 100644 --- a/Runtime/Core/Scripts/Data/AvatarData.cs +++ b/Runtime/Core/Scripts/Data/AvatarData.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; namespace ReadyPlayerMe.Core { @@ -6,5 +7,37 @@ public class AvatarData : MonoBehaviour { public string AvatarId; public AvatarMetadata AvatarMetadata; + + private SkinnedMeshRenderer[] meshes; + + private void Awake() + { + meshes = GetComponentsInChildren(); + } + + 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); + } + } } }