• Unity
  • MaterialPropertyBlock to replace texture of Spine Animation

Hi,

I wanna change the texture of my spine animations, with this forum's advice I made it work by using MaterialPropertyBlock.

But some animations not working properly, some parts of its attachments are not replaced with the new texture.

I checked its slots and attachments, found that they are hidden/showed, I mean when I setting MaterialPropertyBlocks the MeshRenderer's materials did not list these attachments' materials. So I must check the spine's meshrenderer's materials every frame, it's very bad.

Is there any good solutions?

Related Discussions
...
suntabu wrote

I wanna change the texture of my spine animations, with this forum's advice I made it work by using MaterialPropertyBlock.

Which advice have you been following?

suntabu wrote

I checked its slots and attachments, found that they are hidden/showed, I mean when I setting MaterialPropertyBlocks the MeshRenderer's materials did not list these attachments' materials.

I do not quite understand the above sentence. Could you please explain that in different words?

suntabu wrote

So I must check the spine's meshrenderer's materials every frame, it's very bad.

The overhead of checking a few texture reference IDs shoult be negligible, depending on what you are actually checking.

Thanks for your reply.

Harald wrote

Which advice have you been following?

http://esotericsoftware.com/forum/How-to-swap-Materials-in-a-Spine-Animation-7115

Harald wrote

I do not quite understand the above sentence. Could you please explain that in different words?

It means after I set my spine animation's meshrenderer's sharedMaterials with MaterialPropertyBlocks, once the anmation playing, it's sharedMaterials were changed and renewed every frame, so the changes on materials were lost.

Harald wrote

The overhead of checking a few texture reference IDs shoult be negligible, depending on what you are actually checking.

So if I wanna my changes not dismiss, I must set again every frame with MaterialPropertyBlocks. It's not good, need some advices.

This advice is 2.5 years old. Nevertheless, the proper way to override materials is mentioned in Pharan's answer under variant b:

Pharan wrote

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

You can do this e.g. via the following calls:

skeleton.CustomMaterialOverride.Add(fromMaterial, toMaterial);
// if you want to remove one override later:
skeleton.CustomMaterialOverride.Remove(fromMaterial);
// if you need to remove all overrides:
skeleton.CustomMaterialOverride.Clear();

OK, actually I have done this with Override Materials.
But I just want to try MaterialPropertyBlock.

suntabu wrote

OK, actually I have done this with Override Materials.
But I just want to try MaterialPropertyBlock.

suntabu wrote

So if I wanna my changes not dismiss, I must set again every frame with MaterialPropertyBlocks. It's not good, need some advices.

If your attachments change to different atlases, you could try if you can get them all fit into a single atlas that will not change.

If this is not possible, then you will need to set the material property block every frame, and query the assigned materials as you described. Why do you think this is so bad that you want to avoid it at all cost?

9 mjeseci kasnije

Please, I need me too change texture, but in xna runtime
Cristian

5 dana kasnije

YES! :heart:

Great, thanks for getting back to us. 🙂