Skip to content

Commit

Permalink
Avatar Destroy (#319)
Browse files Browse the repository at this point in the history
<!-- 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 -->
  • Loading branch information
srcnalt authored Sep 18, 2024
1 parent 7babd6f commit 70f3e7a
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 70f3e7a

Please sign in to comment.