Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animations play in editor but not in build!

Discussion in 'Scripting' started by Calmax, Sep 9, 2019.

  1. Calmax

    Calmax

    Joined:
    Aug 8, 2017
    Posts:
    26
    Hello all,

    I have animations set up for my player and they work in the editor. However, once I build the scene the animations no longer work and I have no idea why.

    I have looked at other threads and those solutions have not worked for me (i.e. re importing the animations, renaming them and applying root motion).

    Any suggestions will be much appreciated and feel free to ask for any screenshots etc if needed

    thanks
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    I think the first thing to determine is to narrow down where it's breaking. It might be failing to execute the code that runs the animations, the animations themselves might not be exporting, etc. First, can you test to confirm that the code which controls your animator is executing? Either by using Debug.Log and checking the system console, or add a line in that section of code that changes something else that's obvious (maybe moves an object visible from the camera, plays a sound, etc).

    If the code is being run, check Unity's build log to see if the animation data is being included in the build (basically, is the "Animations" line > 0?)

    That info should help narrow down where the fix needs to happen.
     
  3. Calmax

    Calmax

    Joined:
    Aug 8, 2017
    Posts:
    26
    Hi, thanks for the reply.

    I have placed debug lines in the code. There is a running animation that is supposed to work but as I hold L shift the player runs but the run animation itself does not play. I have played again in the editor this time and the debug line does appear. I have attached the code for that event.

    Any suggestins?


    Code (CSharp):
    1.  private void RunInput()
    2.     {
    3.         if (Input.GetKeyDown(KeyCode.LeftShift) && !isRunning)
    4.         {
    5.             isRunning = true;
    6.             StartCoroutine(RunEvent());
    7.         }
    8.         else if (Input.GetKeyUp(KeyCode.LeftShift))
    9.         {
    10.                 isRunning = false;
    11.                 animator.SetBool("IsRunning", false);
    12.                 movementSpeed = 6;
    13.         }
    14.        
    15.     }
    16.  
    17.     private IEnumerator RunEvent()
    18.     {
    19.         Debug.Log("Player Running!");
    20.         animator.SetBool("IsRunning", true);
    21.         movementSpeed = 10;
    22.         yield return null;
    23.     }
    24. }
     
  4. cshamback

    cshamback

    Joined:
    Sep 10, 2021
    Posts:
    1
    I know I'm a few years late to this, but I had no luck finding answers online so I thought I'd post what I came up with when I solved it myself. Personally, my blend tree relied on a velocity calculated in the class that controlled character movement.
    This was calculated in FixedUpdate, not Update: velocity = (position from current frame - position from previous frame) / Time.fixedDeltaTime.
    The difference between the previous and current position was too small so it registered as velocity = 0, so I moved the calculation to Update instead but kept the .fixedDeltaTime (rather than using .deltaTime). This fixed the issue and my animations played like they did in the editor.
     
    lagonz and Chubzdoomer like this.