• Unity
  • How to swap Materials in a Spine Animation

Related Discussions
...

Hey all. I've created a spine animation for one of my little characters in unity (idle/running/attacking).

I want to have variants of this character running around with a DIFFERENT material but using all of the same animations.

Image removed due to the lack of support for HTTPS. | Show Anyway

I've tried creating a new Spine SkeletonData in Unity and dragging a new Atlas with the new material onto it, but upon putting the SkeletonData into a Spine Animation in the scene, I get a NullReferenceException.

NullReferenceException: Object reference not set to an instance of an object
Spine.Unity.SkeletonRenderer.LateUpdate () (at Assets/spine-unity/Assets/spine-unity/SkeletonRenderer.cs:321)
Spine.Unity.SkeletonRenderer.Initialize (Boolean overwrite) (at Assets/spine-unity/Assets/spine-unity/SkeletonRenderer.cs:220)
Spine.Unity.SkeletonAnimation.Initialize (Boolean overwrite) (at Assets/spine-unity/Assets/spine-unity/SkeletonAnimation.cs:139)
Spine.Unity.Editor.SkeletonRendererInspector.DrawInspectorGUI () (at Assets/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs:104)
Spine.Unity.Editor.SkeletonAnimationInspector.DrawInspectorGUI () (at Assets/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs:50)
Spine.Unity.Editor.SkeletonRendererInspector.OnInspectorGUI () (at Assets/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs:188)

Any help would be greatly appreciated!
-Spineman

a) If you only need to change the texture or other material properties, I recommend using MaterialPropertyBlock.
https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html
https://docs.unity3d.com/ScriptReference/Renderer.SetPropertyBlock.html

b) If you need whole material replacement, or multi-material handling, or for different shaders, I recommend CustomMaterialOverride:

void Start () {
     GetComponent<SkeletonAnimation>().CustomMaterialOverride.Add(originalMaterial, replacementMaterial);
}