Search Unity

Question SetBool works in test but not when published.

Discussion in 'Animation' started by HungryCatGames, Oct 21, 2022.

  1. HungryCatGames

    HungryCatGames

    Joined:
    Jun 24, 2020
    Posts:
    40
    I've got a game I'm working on for android. When I run it through Remote it works fine. Animations kick off, games plays as expected. I then do a Build and Run and push it out to the device as an app and the animations no longer work. Throwing some debug stuff in the code and I've got this:

    Code (CSharp):
    1.   MessageText.GetComponent<TextMeshProUGUI>().text = "Did W move #1";
    2. PlayerAnimator.SetBool("Walk", true);
    3.                         MessageText.GetComponent<TextMeshProUGUI>().text = "Did W move #2";
    When I run this directly on the Android device I get the Move#1 message but I never get the move #2 message. When I run it tethered it works just fine.

    So why is the Animator.SetBool not working? This seems a pretty basic statement for the system to some how get stuck or fail to execute.
     
  2. HungryCatGames

    HungryCatGames

    Joined:
    Jun 24, 2020
    Posts:
    40
    I fixed it. For anyone else who runs into something similar, here is what happened. Lots of testing and when I set the animator in Unity instead of in code it animated. Still didn't move (another issue) but at least the animations were kicking off again. As soon as I went back to GameObject.Find the animations failed to run again.

    A bunch of testing and I determined that my "avatar" object and the one immediately below it were both named the same thing. The animation controller was on the top item.

    What appears to be happening is that in editor it takes the top item, in the hierarchy, and uses that so the game works fine in editor/tethered. However when deployed to the Android as a build (and I suspect if I had built it to other platforms too) it is grabbing the second level down name instead of the top name. That second level name doesn't have an animator on it, isn't positional, at least in a sense of seeing something on screen, etc. So I renamed the top level to something different, updated my code to find this new name and everything started working properly again.