- Editado
Change Mesh Image at Runtime
Hello! First off, I'd just like to say how impressed I am with Spine. I'm an animation guy (Toon Boom Harmony / Maya) turned Game Developer, and this software has simply knocked my socks off. Really well done.
I'm trying to change the image displayed by an animated mesh at runtime in Unity. In Spine, I can do this by changing the path of the animated mesh attachment. In Unity, I can't find a way to do this.
I've tried changing the image with an atlas region attacher, a custom skin, and attachments. These work well to change the sprite but discard the mesh animation. I want the same mesh to animate, but I want to change the image that mesh displays.
To give some context: I'm building a character customizer and want mesh animation AND the ability to cycle through different images for body parts. I'd like support for many different parts: so I'd like to avoid bundling every possible image together in the same Spine scene (but that part can be tackled later).
Can someone help me out with this? Thanks!
07 Jun 2016, 11:05
A little update: Got this working fine by creating lots of linked meshes in Spine and changing between them in Unity using the Chimera script in the examples. However, I'd love to not have to set up every possible image swap as a new linked mesh in Spine.
Since you have a potentially any number of variations on it, the answer may be to instantiate and control your own linked meshes at runtime instead of defining them in Spine.
I'll get back to you on how to do that, I need to review the code related to it.
10 Jun 2016 8:53 am
Here's this sample code for now: https://gist.github.com/pharan/8e082b2645f875e4954073da85ebe072
I didn't know this was possible - thanks! I'll try this out.
10 Jun 2016, 09:47
Alright, I've fired up your sample script and I'm having a problem getting it to recognize the mesh attachment
marley_head_attachment in [default] is not a MeshAttachment.
UnityEngine.Debug:LogError(Object)
<Start>c__Iterator0:MoveNext() (at Assets/Barbarians/Marley2/LinkedMeshSample.cs:30)
Image removed due to the lack of support for HTTPS. | Show Anyway Image removed due to the lack of support for HTTPS. | Show Anyway
Parent attachment is definitely a mesh attachment, but it's not getting recognized as one for some reason? I feel like it's expecting some sort of structure in my spine file that I'm just not cluing in to..
Was it weighted with bones?
In 3.2 and below. a mesh with weights is a WeightedMeshAttachment.
But from 3.3 onward, they'll both be a MeshAttachment no matter what.
Yes, it was weighted with bones! That would be my problem.
Okay great. That should clear it up. Thanks!
Hi guys,
Thanks a bunch Pharan, your code sample is great!
Is there a way to use Unity Sprites instead of Spine atlas assets?
I tried to mash together your code with the SpriteAttacher code, but had no luck so far.
I think I could create a RegionAttachment, like the SpriteAttacher does and then copy the UVs and other properties to get it to work, but I'm sure there is a cleaner way...
BTW, I also got the "not a MeshAttachment" error but it was because I used the wrong skin :giggle:
avrahamy escreveuHi guys,
Thanks a bunch Pharan, your code sample is great!
Is there a way to use Unity Sprites instead of Spine atlas assets?I tried to mash together your code with the SpriteAttacher code, but had no luck so far.
I think I could create a RegionAttachment, like the SpriteAttacher does and then copy the UVs and other properties to get it to work, but I'm sure there is a cleaner way...BTW, I also got the "not a MeshAttachment" error but it was because I used the wrong skin :giggle:
Resurrecting this thread to say I too would also like to know if it would be possible to use Unity Sprites instead of Spine Atlas assets?
Any other new solutions available to swap mesh images at runtime in Unity?