Hi, I'm trying to change the material of a Skeleton_Animation at runtime using CustomMaterialOverride. I'm using latest 4.0 Unity runtime and 4.0 spine software
I have checked the documentation already here: spine-unity Runtime Documentation: Changing Materials Per Instance
From my understanding, the following should just work? I have add Debug.Log(..)s to the code to ensure it is running, and it definitely is, and m_OriginalMaterial does exist, and so does newMaterial
However, even if I set the newMaterial to something like blue water or something, the appearance doesn't change in engine. Am i missing something or doing something wrong?
// Check
if (m_Skeleton_Animation != null)
{
// Check cached
if (m_OriginalMaterial == null)
{
// Store original
m_OriginalMaterial = m_Skeleton_Animation.GetComponent<MeshRenderer>().material;
}
// Override - both these methods don't work?
//m_Skeleton_Animation.CustomMaterialOverride[m_OriginalMaterial] = newMaterial;
m_Skeleton_Animation.CustomMaterialOverride.Add(m_OriginalMaterial, newMaterial);
}
EDIT - SOLVED
I managed to solve this, it was because I was getting .material instead of .sharedMaterial. From what I remember, using .material returns an instanced clone of the material, not the actual original one
It'd be nice if a note on how to actually obtain the original material was added to that documentation snippet, as it was difficult to figure out how to get it - and even then I did it wrong.
Thank you