Search Unity

Question Can't Change Material On GameObject with Animator During Runtime.

Discussion in 'Scripting' started by strangeclouds30853, Sep 6, 2021.

  1. strangeclouds30853

    strangeclouds30853

    Joined:
    Jun 22, 2019
    Posts:
    4
    For some reason I can't change the Materials on my spriteRenderer during runtime via script. I did some testing and this only happens on the gameobjects with an Animator. If I turn the animator off during runtime then I can change it just fine, and turning the animator back on will keep the material. I can't even change the material through the inspector during runtime with the animator on. I can however, change the material, if I change it using animation clip timeline. Anyone know whats going on that is stopping me from changing the material freely?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Animations always win. Doublecheck that nothing in the animation is manipulating anything to do with the Renderer, anywhere anytime in its timeline.

    EDIT: just for curiosity I checked... it certainly does work as advertised. Run enclosed scene.
     

    Attached Files:

    Last edited: Sep 6, 2021
  3. strangeclouds30853

    strangeclouds30853

    Joined:
    Jun 22, 2019
    Posts:
    4
    The animation State only manipulates 2 bones and nothing else.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Weird. Try add a fresh "testing" sprite on one of the bones, see if you can modify that sprite's material.

    I also just tested that the same holds true for sprite renderers. Attached.
     

    Attached Files: