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

Editor sporadically "forgets" about a Mecanim state machine

Discussion in 'Editor & General Support' started by KelsoMRK, Oct 2, 2013.

  1. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Ever since upgrading to 4.2 I've encountered a sporadic error. Here's the scenario.

    My default "idle" state is a blend tree that I use to play a collection of idle animations randomly. I do this by using Start as a coroutine, getting the current animation info, yielding the length of that animation clip, picking a new float at random, and assigning that float to a float property in the Animator to kick off a new animation. Something akin to this:
    Code (csharp):
    1.  
    2. public IEnumerator Start()
    3. {
    4.     this.anim = GetComponentInChildren<Animator>();
    5.     while (true)
    6.     {
    7.         if (IsIdle)
    8.         {
    9.             AnimatorStateInfo info = this.anim.GetCurrentAnimatorStateInfo(0);
    10.             yield return new WaitForSeconds(info.length);
    11.             float newState = Random.Rang(0, 6);
    12.             this.anim.SetFloat("IdleState", newState);
    13.         }
    14.         yield return null;
    15.     }
    16. }
    17.  
    Randomly, this code fails by first stating that 0 is an invalid layer index and that there is no property IdleState. Restarting the editor resolves the issue and if I do a standalone build when the editor is in this forgetful state then the error cascades down to the build - but it's fine otherwise.

    This also seems to coincide with a weird graphical bug where the lines representing transitions in the Animator tab are either missing or very thick.
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Update - the graphical bug is not related to Unity dropping the state machine. Does anyone have any thoughts?
     
  3. RGravity

    RGravity

    Joined:
    Jul 4, 2012
    Posts:
    30
    I know it's not much help but just thought I'd chime in with the fact I am now getting this error sporadically too.
    Luckily restarting the editor seems to fix it but it's still a bit worrying.
     
  4. snowsrfr1

    snowsrfr1

    Joined:
    Nov 4, 2013
    Posts:
    21
    Exact same scenario here. Worse, however, if that if you build executables while this bug is happening in the editor, the error will propagate to your standalone. I think we need a bug, I'm on it.
     
  5. snowsrfr1

    snowsrfr1

    Joined:
    Nov 4, 2013
    Posts:
    21
    Case 573418
     
  6. Callabrator88

    Callabrator88

    Joined:
    Nov 11, 2013
    Posts:
    10
    Any movement from Unity on this issue? I'm seeing the exact same thing. Unity 4.2.2f1. Restarting the editor and rebuilding to devices fixes the issue, only to have it come back once in a while.
     
  7. snowsrfr1

    snowsrfr1

    Joined:
    Nov 4, 2013
    Posts:
    21
    BUMP
    BUMPITY
    BUMP

    Helloooooo Unity folks? Can we please get some support here? Even telling me to go climb a tree would be more helpful than silence!
     
  8. Aurore

    Aurore

    Director of Real-Time Learning

    Joined:
    Aug 1, 2012
    Posts:
    3,106
    Please go climb a tree. :) Just kidding.

    Just sent this along with the bug number to QA. You wouldn't have happened to try it in 4.3?
     
  9. Elkis

    Elkis

    Joined:
    Jun 15, 2013
    Posts:
    87
    I encountered this same issue today. I'm using 4.3.0f4 and restarting Unity fixed it for some models. Restarting it again fixed it completely.
     
  10. Ph0enix

    Ph0enix

    Joined:
    Dec 16, 2013
    Posts:
    13
    Hello,

    I am getting similar error, restarting Unity does not help. While running Stealth demo at some point mesh preview and curves on the right (when I click on transition) become distorted. I am running it on Windows 8

    Here is screenshot

    Update: Opening another project then reopening Stealth demo seemed to fix issue. Weird..

    Another update: When I load Done\DoneScenes\DoneStealth scene it gets broken again :)
     
    Last edited: Dec 31, 2013
  11. joaquine

    joaquine

    Joined:
    Oct 8, 2013
    Posts:
    5
    We are seeing this same bug (the original one about Animator having an invalid layer) and it mostly happens only on a build (Android), but I('ve had it happen in the Editor as well. I didn't need to restart the editor to "fix" it, but just stopping and restarting and it works again. No idea how to make it happen again in the Editor.

    Now, we're also seeing the symptoms of the bug (animations not playing at all) but without any errors at all. doing traces reveals the animator does transition to the proper state, but the state never actually starts playing, and the character is stuck in mecanim's default pose, mid-trough the ground.

    We're using 4.3.1f1. I don't know if this is because of an update, as we've just upgraded our animation system to Mecanim after 4.3 was introduced (though I now kinda wish I had waited a bit longer..)

    Anybody seeing similar issues that can chime in and maybe we find a reliable work-around? Right now it's hit or miss if a build will work on the device at all or not.

    Also, where can I check the status of the reported bug? (Case 573418 )
     
  12. marcfielding

    marcfielding

    Joined:
    Aug 1, 2013
    Posts:
    34
    I've just started getting this, in mecanim theres definately one layer, I have

    void Start () {
    anim = GetComponent<Animator>();
    anim.SetLayerWeight(1,1);

    }

    Was working fine, tried restarting the editor and is still an issue, any ideas anyone?

    I also just tried create new project with the dodgey one open and it wiped my hierarchy...nice
     
    Last edited: Jan 9, 2014
  13. hogwash

    hogwash

    Joined:
    Oct 12, 2012
    Posts:
    117
    I'm also having the same "Invalid layer index" bug on Android. I have 2 layers.
     
  14. trololo

    trololo

    Joined:
    Dec 13, 2012
    Posts:
    17
    It still happen to me! But only when i create a web player build... I have unity 4.5.1f3 and a pro licence. This is very random and very annoying, please fix this!
     
  15. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    470
    I'm getting Invalid Layer Index, as well as Paramater '<name>' does not exist on Animators that were correctly animating characters just seconds before, during the same run of our game in the editor. (v 4.5.3f3). The errors are visible in the Unity Editor, which is serving as a client to a Unity Player running the same build, as a stand alone built server, on the same computer.
     
    Last edited: Aug 27, 2014
  16. Bioniss

    Bioniss

    Joined:
    Oct 27, 2013
    Posts:
    4
    BUMP BUMP BUMP

    We are experiencing the same issue as well. We've seen this problem periodically and this bug is causing us lost time. It's clear that others are experiencing the same behaviour and whilst closing / reopening Unity is a valid way to fix the problem we often don't see the issue until deep into testing locally which is a real headache.

    Can we get some traction on this or at least an update on the status? Or - in the very least an acknowledgement of the bug and why it's occurring.

    I'm using Unity Pro 4.5.1f3.

    Thanks!
    - Toby.
     
  17. Ville

    Ville

    Joined:
    Oct 5, 2012
    Posts:
    19
    Experiencing the same thing as well, opening another project, then returning helps.
     
  18. draxov

    draxov

    Joined:
    Jun 2, 2012
    Posts:
    26
    I too have been experiencing this problem erratically in all versions of unity since 4.1.2, I can't seem to get a 100% repro with it, but certain things seem to exacerbate it.

    Most of the time it happens when building (I'm building for windows), though as I speak it's just happened in the editor after a build.

    The animator seems to become corrupt in some way and any operation on it spits out an "Invalid Layer Index" error or "Invalid Hash" error. The visual of the animator itself seems to be very erratic. The skinned meshes end up in their bind pose when it happens (though in 4.1.2 it was a lot worse, the bones would fly off into a random space, now it just goes to bind pose in 4.5.3)

    Having the animator window open at build time seems to cause it to happen, also the animator I have is rather complicated (several layers, a few sub states, zero-time transitions) and I think this causes some problems, but it happens on simpler animator controllers too, but they do share the zero-time transitions, so that may have something to do with it.

    I can't seem to get a 100% repro with this unfortunately, but because of this erratic nature, it could have something to do with the animator interrupting serialization or something, not sure how it all works internally.
     
  19. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    970
    I have never had this happen in editor but I have had it happen on a build a *lot* of times. Like you said, it seems to be intermittent, in my case rebuilding fixes it. You do a build and it'll be fine, do it again and it'll be broken, do it again and it'll be fine. I have not managed to produce a reliable repro project or even narrow down what on earth is going on. It's been happening since long before our Animator Controller actually got complicated. And on top of that we keep losing the any state transitions in Editor, but that is a known issue with a known workaround until Unity fixes it.
     
  20. kasulogamestudio

    kasulogamestudio

    Joined:
    Mar 22, 2012
    Posts:
    130
    Hello anyone knows if this was solved? We just had this problem, and worse, we sent the version for our Publisher (because here it was not happenning, and then started out from nowhere). We are still using Unity 4.5.2
    Thanks
     
  21. xpander

    xpander

    Joined:
    Oct 1, 2012
    Posts:
    28
    Same here.
    I randomly catch "Invalid Layer Index" error when calling UnityEngine.Animator.Play(). I can't remember it to happen in the Editor mode, but it happens in Standalone Builds and Android / iOS builds.
    Rebuilding the app without reopening editor, fixes it in most cases.
     
  22. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Hi guys, we are aware of this bug, and we are working for a fix in a patch release.

    Until then, the a workaround I can suggest is making sure the Animator window is closed when building the game.

    Please tell me if this fixes the problem !

    pp
     
  23. xpander

    xpander

    Joined:
    Oct 1, 2012
    Posts:
    28
    Hi, pierrepaul.

    I did a further investigation in my project. It nicely reproduces with the following steps:
    1. Open Animator window.
    2. Select some existing Animation Controller in the project, so that its contents are shown in the Animator window.
    3. Close Unity.
    4. Reopen Unity, same project. You should see Animator window opened with last Animation controller details in it.
    5. Build Standalone EXE (Windows 7).
    6. Run EXE.
    After these steps, I always (5 / 5 tests) get "Invalid Layer Index" error, when playing one of my animations (but not all).
    I guess this is also somehow related: animated object is inactive on startup and becomes active some time later, when it is no longer hidden by fog of war.
    When I build EXE second time, it works fine.

    Now, when I close Animator window before building (step 5), it still reproduces. But... If I close Animator window before step 3 and then do all the following steps, it works ok.

    However, when I've tried to reproduce it in a small test project with no luck.

    [UPD]
    All builds were made in "Development mode" with "Scripts debugging" enabled.
     
    Last edited: Oct 14, 2014
  24. M-Palko

    M-Palko

    Joined:
    Jan 22, 2013
    Posts:
    7
    Bumping this thread a bit, but we seem to be having this issue as of 4.5.5.

    It doesn't seem to happen when built from OSX, but does happen frequently when building to Android from windows. It doesn't seem to be related to having the animator window open, as it still occurs on our automated builds that are run from commandline with "-batchmode"
     
  25. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    970
    If I remember rightly, the fix to this is in one of the patch releases, so try installing 4.5.5p5.
     
  26. M-Palko

    M-Palko

    Joined:
    Jan 22, 2013
    Posts:
    7
    4.5.5 Patch 3 has the note:
    • (597261) - Mecanim: Fixed AnimatorController not being built properly when used in prefabs.
    I'm assuming that's the issue we are facing, as our character is setup as a prefab. Our build server is running Patch 4 atm, so it shouldn't be getting this issue. I'll verify today, but it seems like we're still getting it on P4.
     
  27. dimitroff

    dimitroff

    Joined:
    Apr 3, 2013
    Posts:
    131
    Just to report that I have the same problem, when building for OSX with 4.6c2. It happens rarely,but it does. I receive the following error "Invalid Layer Index", after Instantiating a character Prefab, containing the Animator in a child.

    Any idea how to temporarily fix this?
     
  28. M-Palko

    M-Palko

    Joined:
    Jan 22, 2013
    Posts:
    7
    Don't seem to be getting the error anymore, so 4.5.5p3 should fix it for anyone else having the issue.

    @dimitroff: Restarting unity and doing another build usually fixes it if it does occur.
     
  29. LessThanEpic

    LessThanEpic

    Joined:
    Aug 22, 2014
    Posts:
    13
    We were experiencing a similar issue when building asset bundles. If you build your asset bundle from the editor (via an editor script or what not) and the Animator window is open when the bundle is built then trying to use the Animator from the bundle will result in an invalid layer index exception. Had no idea what was causing the problem until I found this thread and closing the Animator window before I built the bundle fixed the issue.
     
  30. draxov

    draxov

    Joined:
    Jun 2, 2012
    Posts:
    26
    I've been using 4.6.1 for a while now, and haven't experienced it since, seems like it's fixed in that, at least for build. Not sure about asset bundles though.
     
  31. RoguePointer

    RoguePointer

    Joined:
    Oct 15, 2015
    Posts:
    13
    Bump. I just encountered this issue. Restarting unity helped. But looks like the bug isn't as fixed as first presumed.