Unity 2017 Material animations broken

Slate Forums Support Unity 2017 Material animations broken

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1530
    nshelton
    Participant

    Hello, Love using SLATE, been using it for about a year now. I use it for mostly animating material shaders.
    However in Unity 2017 I have a big problem, because SLATE can no longer handle animating multiple properties on a material at the same time.

    When animating one material parameter, things are fine.

    When animating two material parameters, only the animation that starts later has any effect. After the second animation is done (Color in this case) then the first animation comes back in and works. See how it gets 100% glossy, only after the red animation clip is finished. The animation shows 100% glossy at the 2s mark, but that doesn’t happen until ~4s when the color animation stops.

    This happens because the second animation clip instantiates a new material from whatever the first animation clip had created and assigns it to the renderer. Then the reference that the first clip has is no longer the active material, so its updates don’t work until the second clip is calls OnExit() and restores the original sharedMat.

    TwoParameterAnimation

    Even worse, If I have two animations where they are staggered, the material gets totally destroyed upon completion of the second animation. This is because the second animation clip gets a reference to the first animation clip’s material as its sharedMat and restores the sharedMat when it is finished OnExit(), but the first animation clip has already destroyed this. So SLATE assigns a null material to the renderer, totally breaking it.

    StaggeredAnimation

    If I make the two material animation clips the exact same length, so that they start and end at the same frame, then I only get one of the parameters animating, and the material still turns to null at the end.

    It seems like in Unity 5.6, there was something special about accessing renderer.sharedMaterial that somehow made this code work correctly. But in 2017, the sharedMaterial isn’t updated in the same way, and can’t be used by more than one material animator at a time. This is kind of bad because we rely on many material animations across our game and these are subtly broken in all our SLATE cutscenes (subtly because the one parameter still works).

    So in the meantime, I have created a custom Clip that just modifies the renderer.sharedMaterial, which is fine for now but requires me to create a separate material for every object I want to animate (not ideal). To really fix this, you need to have a reference to one material for each group, and have all material animator clips reference that material instead of instantiating a new material for each clip.

    Are you aware of this unity 2017 material issue?
    Is there a workaround?
    Am I doing something wrong in using SLATE in this way?
    Is animating multiple material parameters at once supported?

    Thanks for your time! Hope this helps in some way. I can supply a sample project but This behavior should be easy to reproduce on Unity 2017.3.

    -Nick

    Attachments:
    You must be logged in to view attached files.
    #1534
    Gavalakis
    Keymaster

    Hello,

    Thanks for the detailed post and report.
    I wasn’t aware that this did not work in Unity 2017.
    Hmm. I think another solution around this, would be to change the action clips, to work with the sharedMaterial directly instead of instantiating a new material. This will avoid all this fuzzy instantiation and material handling manually, but on the other will affect all objects using that material.
    I could however use “sharedMaterial” in editor only for previewing and rather use “material” (thus instance) in runtime.

    Let me know what you think.
    Thanks.

    Join us on Discord: https://discord.gg/97q2Rjh

    #1536
    nshelton
    Participant

    Yes, I have created a new action clip that just uses shared material, which works fine for me now.

    But it would be nice to get an instance of the material, if it worked with many animations.

    #1597
    sugoidev
    Participant

    Confirming the same issue on Unity 2018.2 right now. It also broke my material when I had two clips of the same length changing properties. They could not restore the material when scrubbing in reverse and the clips began throwing null ref exceptions when they could not instantiate the temp material.

    Working directly with the sharedMaterial works, but I’m not sure if it’s the best way.

    #1600
    Gavalakis
    Keymaster

    Hello,

    I have attached here the “fixed” versions of material-based clips.
    For now, in editor the sharedmaterial is used, while in runtime the instanced material. This is the safest approach until determined a better workaround and will continue with this change in the next version.

    Thanks!

    Join us on Discord: https://discord.gg/97q2Rjh

    Attachments:
    You must be logged in to view attached files.
    #1603
    sugoidev
    Participant

    Awesome, thanks!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.