Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question [SOLVED] Material swapping animation working in editor but not in build

Discussion in 'Animation' started by christinapetpersonal, Jan 31, 2023.

  1. christinapetpersonal

    christinapetpersonal

    Joined:
    Jan 6, 2023
    Posts:
    3
    Hello, I'd really love some help as this is for a uni project and I have a deadline coming. I'm making a small game with cutscenes using timelines, in which I have two characters blinking throughout the duration of each cutscene via material swapping on the model, following this tutorial:



    This works perfectly in the editor and when I go into play mode. However, in the build of the game, the blinking animations just... don't play. Only the first material in the list is kept and the others are seemingly discarded, so facial animations don't play. All the other animations (characters moving, etc.) play just fine and it's only this that has the issue, it happens to both characters in and all the cutscenes so I know the issue lies within either the material swapping itself or a setting in the build. I'm imagining it's a simple fix, I just can't figure out what exactly it is.

    EDIT: I figured out a solution/workaround. I kept a single material slot and just swapped the materials back and forth to create an animation. This works in the build at last, which I'm really happy about. For some reason the build just doesn't like objects with multiple materials for some reason... I don't think I can figure out why but this works at least.
     
    Last edited: Feb 6, 2023
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Just a suggestion - can't you make this some other way, like using an overlay objects which have the eyes and put these near the surface, and then switch these eye objects on and off instead of material switching.
     
  3. christinapetpersonal

    christinapetpersonal

    Joined:
    Jan 6, 2023
    Posts:
    3
    Not really sure how that would change things. I could try, but it would basically be the exact same thing, just on a different mesh. Plus I've already set up all of the blinking animations across my cutscenes, again, they all play okay in the editor/play mode. Only the build is giving me this problem, which makes me think it must be a setting that needs to be checked or something.
     
    Last edited: Feb 2, 2023
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Have you tried to force Unity to include the shader in the build? Perhaps a missing shader is what's causing your material to fail runtime.

    You can do that in the Project settings\Graphics.

    i.e. try to include the shader used in that material for the eyes, make a new build and see if that helps.
     
  5. christinapetpersonal

    christinapetpersonal

    Joined:
    Jan 6, 2023
    Posts:
    3
    Tried it, yeah. Doesn't seem to change much, unfortunately. I doubt it's the shaders since more game objects share the same shader, plus the materials are in the build, they're just not animating (ie. Element 0 is eyes open and Element 1 is eyes closed. The cutscene plays in the build keeping Element 0 without switching between them like it does in the editor. It's almost like the build doesn't recognize the keyframes/animation being there.)