Search Unity

Unable to change color of object via script after legacy animation.

Discussion in 'Animation' started by laurinjahns, Mar 9, 2020.

  1. laurinjahns

    laurinjahns

    Joined:
    Mar 13, 2019
    Posts:
    2
    So I'm trying to change the color of my GameObject in Update() every couple of seconds via Script, which works fine and everything.

    Now I am playing an animation animating color changes for 8.5 seconds, and afterwards, if I try to change the color again in the regular interval, it won't accept it, despite the new color being displayed in the editor like this:

    upload_2020-3-9_16-6-6.png

    The color should be red, but is actually blue in the game.

    I have tried:
    1. Using the Legacy Animation system with Play(anim);
    2. Using the Animator Controller and triggering the animation via SetTrigger(), and in the End: ResetTrigger();
    3. Disabling the animation property after the animation is done.
    4. Setting the Wrap Mode of the Animation to once.
    5. Changing the shader of the object (Its no shader problem)
    6. Putting the color changing code in LateUpdate()
    7. Adding an Animation Event at the end of my Animation, setting the color to a different value.

    It must have something to do with the Animation never finishing, because the Object always remains the last animated keyframe color, and the animation cant start again, however if I use the animator, the animation state clearly finishes.

    Can someone please help me, I have been biting my nails out on this problem for days.

    EDIT: The Problem does not seem to originate from the Animation itself, because if i set the last state of the animation to (1,1,1,1) white, full alpha, it still goes to blue after the animation as if it was set from somewhere else.

    EDIT: I know now that the problem is that you have to use a sharedMaterial if you edit it from multiple places at the same time, else unity creates instances of the same material, that cant be changed, but in the unity animation editor, you cant animate shared material.
     

    Attached Files:

    Last edited: Mar 10, 2020