• Runtimes
  • Swapping materials at runtime Unity C#

Related Discussions
...

I recently switched from Smooth Moves in Unity to using Spine because the animation tools are far more advanced and I have access to the runtime source.

There is one last thing I need to replace in the change over ... that is a my "freeze effect" which pauses any current animation and swaps all materials on the object to use new materials that use a different shader which turns all textures to grayscale and then color key to a blue ice-like color.

Only thing is, I'm not sure how I should be changing the materials for a single game object which has a SkeletonAnimation component. Smooth Moves had given me an API to swap a single material as well as restore all materials to their original.

Where are the materials I should be changing in the Spine data for a single object instance?

Thanks.


Colin

http://esotericsoftware.com/spine/files ... iagram.png
Materials come from the atlas. A RegionAttachment has RendererObject which (when using AtlasAttachmentLoader (which is used by default)) is an AtlasRegion which has an AtlasPage which has a rendererObject which is a Unity Material. A RegionAttachment is stored in a Skin which is stored in the SkeletonData. The SkeletonData and all the objects it contains are stateless. A single SkeletonData can be used for many Skeleton instances. This means if you changed the material for an AtlasPage then it would change for all Skeleton instances that use that AtlasPage. If you have only one Skeleton instance for the SkeletonData you want to modify, this isn't an issue.

3 months later

I too am looking at switching from SmoothMoves to Spine. Does this response mean that there is not a way to change a texture of one bone at runtime? My game's core aspect is avatar customization which relies on each bone of each avatar instance to be different. Is this possible with Spine?

Sure it is. SkeletonData is separate from Skeleton so that you can load the SkeletonData (which includes all animations, etc) once, and then create as many Skeletons as you want. You could also have a separate SkeletonData for each Skeleton.

The OP asked to change the texture for an attachment. In Spine the usual way to do that is to just show a different attachment that has the texture you want. You can create attachments on the fly, programmatically.