Related Discussions
...

Hello everyone,

I have multiple gameobject instantiated with one gameobject template.
Sometimes I don't use them and I'd like to unload the spine texture on the gameobject template.
So I do it this way, and it works fine:

MeshRenderer oMeshRenderer = m_oGameObjectTemplate.GetComponent<MeshRenderer>();
Resources.UnloadAsset( oMeshRenderer.material.mainTexture )

But when I want to reload it, it doesn't:

Texture oTexture = (Texture) Resources.Load( sSpineTexturePath, typeof( Texture ) );
MeshRenderer oMeshRenderer = m_oGameObjectTemplate.GetComponent<MeshRenderer>();
oMeshRenderer.material.mainTexture = oTexture;

My gameobjects are still not visible after doing that.

I know the correct way would be to reload a "SkeletonDataAsset", and call "Initialize" on the "SkeletonAnimation"
but it slows down the loop, and I cannot do it in another thread (thanks unity). So I would like to do it this way, with only loading / unloading the resource.

Instead of accessing materials via the MeshRenderer component, we would recommend to use SkeletonDataAsset.atlasAssets instead as follows:

Material material = skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial; // or via .Materials

Accessing materials of the MeshRenderer is not reliable as it's a result of the atlas pages required by the currently active attachments. So e.g. when no attachments are visible in a frame, no material will be assigned.

Glad to hear, thanks for getting back to us. 🙂