• Unity
  • Issue with material swapping / greyscale shader

  • Modifié
Related Discussions
...

Hello

I'm having some trouble with materal swapping on my skeletons

I have several skeleton that have an original material and a copy of this material which is using a different shader ( the awesome skeleton-greyscale shader provider by esoteric ).

From the research I did, this is how I should swap materials in skeleton :

//Greyscale on
m_Controller.Skeleton.CustomMaterialOverride.Add(m_OriginalMat, m_GrayScaleMat);
//Greyscale off
Skeleton.CustomMaterialOverride.Clear();

however this doesn't have any effect on my visual and material remain the original one :

I tried doing the following thing instead :

//on
Skeleton.Renderer.sharedMaterial = m_GrayScaleMat;
//off
Skeleton.Renderer.sharedMaterial = m_OriginalMat;

this actually works but not on all objects strangely.

maybe I'm missing something, could you please shed some light on me 🙂

Unfortunately we could not reproduce your problem - are you sure that the Clear() call is issued at the proper skeleton?

This short test-component works perfectly for us:

public class testCustomMaterialOverride : MonoBehaviour {

   public Material fromMaterial;
   public Material toMaterial;

   IEnumerator Start() {
      var skeleton = this.GetComponent<Spine.Unity.SkeletonAnimation>();
      yield return new WaitForSeconds(1.0f);
      skeleton.CustomMaterialOverride.Add(fromMaterial, toMaterial);
      yield return new WaitForSeconds(1.0f);
      skeleton.CustomMaterialOverride.Clear();
   }
}

Hi thanks for your answer, I found my problem :

I was doing something like this :

m_OriginalMat = GetComponent<MeshRenderer>().material;

now am directy referencing the material as a public properties and this script works.

Thanks for getting back to us, glad you found the problem!