Skip to content

Commit 70f3e7a

Browse files
authored
Avatar Destroy (#319)
<!-- Copy the TICKETID for this task from Jira and add it to the PR name in brackets --> <!-- PR name should look like: [TICKETID] My Pull Request --> <!-- Add link for the ticket here editing the TICKETID--> ## [TICKETID](https://ready-player-me.atlassian.net/browse/TICKETID) ## Description - Briefly describe what this change will do <!-- Fill the section below with Added, Updated and Removed information. --> <!-- If there is no item under one of the lists remove it's title. --> <!-- Testability --> ## How to Test - Add steps to locally test these changes <!-- Update your progress with the task here --> ## Checklist - [ ] Tests written or updated for the changes. - [ ] Documentation is updated. - [ ] Changelog is updated. <!--- Remember to copy the Changes Section into the commit message when you close the PR -->
1 parent 7babd6f commit 70f3e7a

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
1-
using UnityEngine;
1+
using System;
2+
using UnityEngine;
23

34
namespace ReadyPlayerMe.Core
45
{
56
public class AvatarData : MonoBehaviour
67
{
78
public string AvatarId;
89
public AvatarMetadata AvatarMetadata;
10+
11+
private SkinnedMeshRenderer[] meshes;
12+
13+
private void Awake()
14+
{
15+
meshes = GetComponentsInChildren<SkinnedMeshRenderer>();
16+
}
17+
18+
private void OnDestroy()
19+
{
20+
foreach (var mesh in meshes)
21+
{
22+
var materials = mesh.sharedMaterials;
23+
24+
foreach (var material in materials)
25+
{
26+
if(material == null) continue;
27+
28+
foreach (var property in material.GetTexturePropertyNames())
29+
{
30+
Texture texture = material.GetTexture(property);
31+
32+
if(texture == null) continue;
33+
34+
Destroy(texture);
35+
}
36+
Destroy(material);
37+
}
38+
39+
Destroy(mesh.sharedMesh);
40+
}
41+
}
942
}
1043
}

0 commit comments

Comments
 (0)