TedNindo

Hey,

I try to change the material on my Spine Enemy. To achieve that I found here in the forum to use the SkeletonRendererCustomMaterials. So, I added this component plus added the original Material and the new Material to the first list entry of the CustomMaterialOverrides List.

When I use the bool in the inspector "Override Disabled" it does exactly what I want. It changes the materials back and forth (true/false).






But now I am not able to access exactly this function via code. I tried to get this component(SkeletonRendererCustomMaterials) using the needed namespace but I am not sure why I can't access this bool.
I somehow guess this is not the way this is intended and therefore this is somehow protected. But it seems so easier via the inspector.

Is there anything you can recommend?

Thank you very much!

Using Spine 3.6.5 and the corresponding runtimes.

---

I would like to add an additional question. When the material is changed to the override material (Skeleton PMA Screen) I would like to change the Tint Color via code.

But this here does not do a thing:
myMeshRenderer.material.SetColor("_Color", new Color(1,0,0,0));
I also tried it this way:
myMeshRenderer.material.color = new Color(1,0,0,0);
If I use debug.log to get info about Color like this:
Debug.Log("Change Color: Current color is: " + myMeshRenderer.material.color);
I get the right values so I guess I have the right material and the right attribute on the shader.

Do you have any ideas?
TedNindo
  • Mesajlar: 46

Harald

TedNindo yazdı:I somehow guess this is not the way this is intended and therefore this is somehow protected. But it seems so easier via the inspector.
Yes, it is indeed not intended to be accessed via code, see
spine-unity Runtime Documentation: SkeletonRendererCustomMaterials
spine-unity documentation page yazdı:Note: This component is not intended to be interfaced through code. To dynamically set materials for your SkeletonRenderer through code, you can directly access SkeletonRenderer.CustomMaterialOverride for material array overrides and SkeletonRenderer.CustomSlotMaterials for slot material overrides.
TedNindo yazdı:But this here does not do a thing:
myMeshRenderer.material.SetColor("_Color", new Color(1,0,0,0));
In general it is not recommended to access meshRenderer.material, since:
  1. it creates a material copy each time (compared to .sharedMaterial which does not),
  2. you might call it too early or too late in script update order. See documentation here for details on event hooks to use.
  3. in your case you would rather set Material properties at your assigned CustomOverrideMaterial, instead of the MeshRenderer's materials.

In general the documentation section here might answer some more potential questions that might arise:
spine-unity Runtime Documentation: Changing Materials Per Instance
Kullanıcı avatarı
Harald

Harri
  • Mesajlar: 4002

TedNindo

Harald, thank you for your help. I think I had a totally wrong understanding of how this works. Doing the research you have linked here. I stumbled over this post which provided a very easy solution!

Thank you for your help! The switching between the materials does work now. The rest will work eventually too!
TedNindo
  • Mesajlar: 46

Harald

Glad to hear you've figured it out, thanks for your kind words! :)
Kullanıcı avatarı
Harald

Harri
  • Mesajlar: 4002


Dön Unity