• RuntimesUnity
  • unity - add custom material to skeleton mecanim

I am trying to figure out how to add custom material to Spine2d object.

in unity I created a new Shader Graph, from this shader I created a new material and changed in the inspector the shader to "Spine/Skeleton".

I tried to add this material to the Spine2d gameObject (skeleton mecanim) but without any success.

so I opened the skeleton_Atlas.asset and add the material there:

(my skeleton_SkeletonData.asset is use this skeleton_Atlas.asset)

in the spine2d game object, under the skeleton_mecanim script I tried to reload my sekelton_SkeletonData.asset by clicking on the reload button. but the additional material that was added to skeleton_Atlas.asset wasn't updated in the spine2d gameobject (under the Mesh renderer).

what I am missing?
how can I add a new material to exists spine2d skeleton mecanim?

Related Discussions
...

To add a custom material to a Spine2D object in Unity, especially when using SkeletonMecanim, you need to follow a specific process. Here are the steps you should take:

  1. Create the Material: Ensure your custom material is correctly set up with the Shader Graph and that it uses the "Spine/Skeleton" shader.

  2. Assign the Material: Instead of directly modifying the MeshRenderer or the skeleton_Atlas.asset, you should use the SkeletonRendererCustomMaterials component to override the materials. This is the recommended approach as directly modifying the MeshRenderer's materials often does not work as expected.

  3. Using SkeletonRendererCustomMaterials:

    • Add the SkeletonRendererCustomMaterials component to your Spine GameObject.
    • In the SkeletonRendererCustomMaterials component, you can specify the original material and the replacement material. This will ensure that your custom material is used instead of the default one.

Here is a step-by-step guide:

  1. Add the SkeletonRendererCustomMaterials Component:

    • Select your Spine GameObject in the Unity Editor.
    • Click on Add Component and search for SkeletonRendererCustomMaterials.
    • Add this component to your GameObject.
  2. Configure the Material Override:

    • In the SkeletonRendererCustomMaterials component, click on Add Material Override.
    • In the Original Material field, select the material you want to replace (the default material used by your Spine skeleton).
    • In the Replacement Material field, select your custom material created with Shader Graph.
  3. Verify the Setup:

    • Ensure that the SkeletonMecanim component is correctly referencing your skeleton_SkeletonData.asset.
    • Click the Reload button on the SkeletonMecanim component to refresh the skeleton data.

By following these steps, your custom material should be applied to the Spine2D object correctly.

For more detailed information, you can refer to the spine-unity documentation on materials and changing materials per instance.

nice bot 🙂
what if I don't want to replace the original material, just add another one?
do I need to add overwrite between my custom material and my custom material?

I tried to use SkeletonRendererCustomMaterials, I overwrite the original skeleton_material with my custom material. in run time when I try to fetch the material from the mesh renderer I still got the 'skeleton_material'. instead of my custom material, it feels like the overwrite never happen.
when I tried to fetch the material from the SkeletonRendererCustomMaterials I got my custom material. I tried to change one of the float variables in the material (to get flash effect) it looks like I am able to change the value, the problem is that I don't see any flash effect in the game. I tried my material on non spine2d object and it works well.

any suggestions?

  • Misaki и Harald ответили на это сообщение.

    coldpain I am afraid that our Unity expert, Harald, is on vacation and will not be able to respond until Wednesday. We appreciate your patience until he returns.

    • Изменено

    coldpain what if I don't want to replace the original material, just add another one?

    This makes no sense as such, when should your material be used if you just add it to end of the already complete list? Each atlas page has it's associated material, and when an active attachment requires e.g. the second atlas page, the second material will be used. However no existing atlas page will suddenly reference your added material.

    in run time when I try to fetch the material from the mesh renderer I still got the 'skeleton_material'. instead of my custom material, it feels like the overwrite never happen.

    You might be calling the respective code too early then, before the replacement happened.
    What do you mean by "it feels like the overwrite never happen", do you see the override material being applied, or do you see the original material on the skeleton?

    If you want to replace materials at runtime, please see the documentation here.
    As the documentation reads, you might want to use SkeletonRenderer.CustomMaterialOverride directly instead of the SkeletonRendererCustomMaterials component in some use-cases.