Search Unity

StateMachineBehaviour Scripts go missing after Reimport all.

Discussion in 'Animation' started by jrhowa, Jul 1, 2015.

  1. jrhowa

    jrhowa

    Joined:
    Feb 3, 2015
    Posts:
    5
    I have a few StateMachineBehaviour scripts that i have attached to a few nodes in my player animator state machine. After a reimport they go missing and have to be added back in ..

    Any idea as to why?

    Thanks.
     
  2. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Looks like a bug. I also found my StateMachineBehaviours surprisingly missing a couple of times, more than I wanted to. I'd filed a bug report, but I don't know how to reproduce it. I just tried to Reimport All - didn't help, behaviours didn't disappear.
     
  3. U-GeeN

    U-GeeN

    Joined:
    Mar 22, 2015
    Posts:
    95
    Yes I had that problem, too. Scared the hell out of me when I noticed that my Animator wasn't working the next day I finally got all done...
    Bad, animator... bad...
     
  4. stefankohl

    stefankohl

    Joined:
    May 30, 2014
    Posts:
    53
    I also encountered this problem several times and it is annoying as hell, since I use many animator controllers and state machine behaviours. Has the Unity dev-team already take notice of this issue?
     
  5. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    this is not something we are aware of, if you can reproduce this please log a bug with project.

    Thanks
     
  6. U-GeeN

    U-GeeN

    Joined:
    Mar 22, 2015
    Posts:
    95
    I tried to save, load, export and reimport again and couldn't reproduce it. Seems like it is ok now.
     
  7. stefankohl

    stefankohl

    Joined:
    May 30, 2014
    Posts:
    53
    It happened to me once after I was deleting the Library folder, but I was not able to reproduce it intentionally.
     
  8. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    There was a week or two between June and July during which my StateMachineBehaviours regulary went missing, but then the problem suddenly disappeared. Either it was fixed or I just stopped doing what I was doing.
     
  9. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Oops, it happened to me again. And again I have no idea of what may have caused it. Unity 5.1.2f1

    After I have restored all the state machine behaviors and saved the changes, the diff looks like this:
     

    Attached Files:

    • 1.PNG
      1.PNG
      File size:
      42.4 KB
      Views:
      1,090
    • 2.PNG
      2.PNG
      File size:
      33.7 KB
      Views:
      1,083
  10. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    We have found one way to reproduce this bug,We did change how StateMachineBehaviour(SMB) were serialized while in 5.0 beta cycle. So any project created with 5.0 alpha or beta won't reload SMB.

    But I guess that most of you are only working in 5.1 so there is probably something else.

    @alexzzzz, do you still have the meta file before your restoration step? I would like to confirm that your project is saved with the new format

    before SMB were saved like:
    Code (CSharp):
    1.  
    2. m_Behaviours:
    3.   - m_Behaviour: {fileID: 11409215}
    4.   - m_Behaviour: {fileID: 11493879}
    5.  
    but now they are saved like:
    Code (CSharp):
    1.  
    2. m_StateMachineBehaviours:
    3.   - {fileID: 11409215}
    4.   - {fileID: 11493879}
    5.  
     
  11. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Well, yes, but there was no changes in meta files.

    TortoiseHg shows me that the animation controller's meta file and most of my SMB's meta files were created 7 months ago and haven't been changed since.

    The animation controller's meta looks like this:
    Code (csharp):
    1. fileFormatVersion: 2
    2. guid: 6f2de9b77f3929f40951094e3034ca99
    3. NativeFormatImporter:
    4.   userData:
    5.   assetBundleName:
    One of the SMB's meta:
    Code (csharp):
    1. fileFormatVersion: 2
    2. guid: 40a1da940cec3114fb4d88215aaad645
    3. MonoImporter:
    4.   serializedVersion: 2
    5.   defaultReferences: []
    6.   executionOrder: 0
    7.   icon: {instanceID: 0}
    8.   userData:
    9.   assetBundleName:
    The animation controller content before and after the restoration is in Controller.zip. Their diff:
    diff1.PNG diff2.PNG
     

    Attached Files:

  12. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    both file version use the new way to store SMB, so it not related to this issue, it something else
     
  13. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Random notes:

    1. Since state machine behaviors were introduced in Unity 5 and since my behaviors were created on December 17, 2014, they had to be originally created in one of the Unity 5 betas.

    2. My repository contains Assets and ProjectSettings folders and all the meta files. When my SMBs disappear and I roll the repository one day back - it doesn't help, the behaviors don't reappear.

    3. When behaviors disappear, it doesn't look like they were attached but now are missing, it looks like they haven't been attached at all.

    4. When I restore the missing SMBs, the animation controller file is the only file that changes.
     
  14. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    It easy to check if it's the same issue
    search in your meta file for any occurance of
    m_Behaviours:
    - m_Behaviour: {fileID: xxxxxxxxx}
    - m_Behaviour: {fileID: xxxxxxxxx}
    if you don't find any occurance then it something else
     
  15. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    My .controller files mention m_Behaviours in m_AnimatorLayers section. Is it ok?

    Code (csharp):
    1. AnimatorController:
    2.   ...
    3.   m_AnimatorLayers:
    4.   - serializedVersion: 5
    5.     m_Name: Base Layer
    6.     m_StateMachine: {fileID: 110771502}
    7.     m_Mask: {fileID: 0}
    8.     m_Motions: []
    9.     m_Behaviours: []
    10.     ...
     
  16. skeletromp

    skeletromp

    Joined:
    Aug 31, 2014
    Posts:
    3
    I'm having this same problem in 5.3.5f1. I can't pin down when exactly it happens. Just eventually the scripts are no longer attached to the state machine and functionality stops. It has happened three times now in the course of a few weeks.
     
    jwinn likes this.
  17. paraself

    paraself

    Joined:
    Jun 30, 2012
    Posts:
    139
    Same issue here on 5.3.5f1. I had a couple of compiler errors then I fixed them. After that all the SMB go missing...Terribly.
     
  18. FlyAnvil

    FlyAnvil

    Joined:
    Aug 14, 2013
    Posts:
    9
    Same! A nightmare! MEND URGENT!
     
  19. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    This happens at random intervals. All state machine behaviours in a controller will disappear. I haven't been able to see what causes it, but I have noticed that just after it happens, some of the states that used to have behaviours on them will have "missing behaviours", ie. there's a behaviour there, but Unity isn't displaying which it is.

    I really can't reproduce it, and I don't really have any reason to investigate since I can just revert the controller in git. Still, this is one bad bug. Data loss is never fun.
     
  20. jwinn

    jwinn

    Joined:
    Sep 1, 2012
    Posts:
    88
    Same problem here. Very frequently I would lose ALL state machine behaviours, and would have to revert the Animator Controller file using version control. I was hoping this was fixed in 5.4; I'm updating today to see if it's at all better.
     
  21. Pukami

    Pukami

    Joined:
    Mar 21, 2016
    Posts:
    1
    I also got this problem (5.3.5f), but I was able to reproduce it multiple times and just sent a bug report to Unity about it! Hopefully they reply soon and are able to fix the problem.

    I was able to reproduce it by creating a new script in my scripts folder, which prompted Visual Studios to tell me that the environment was modified and then clicking "Reimport All" when it told me to, then I intentionally caused a random compile error in one of my other scripts. After saving and reloading the Unity editor, the compile error shows up, but with two other errors telling me some object that was destroyed is trying to be referenced, which was caused by the behavior scripts suddenly disappearing.

    I'm not sure if that's the same bug as everyone else, but I have a feeling that the bug is being caused by some sort of issue between the link of the Unity Editor and Visual Studios :/
     
  22. jwinn

    jwinn

    Joined:
    Sep 1, 2012
    Posts:
    88
    I just had this happen again, while working in 5.4.0f3. To be clear, I am not doing any reimports like the original poster mentioned. I was simply editing scripts in Visual Studio, and not touching my Animator Controller. It seems to happen when working on a script that has an error, and after fixing the error and Unity has recompiled. All states with StateMachineBehaviours have blank "Script" "None (MonoScript)" attached. Same as @Baste mentioned.

    Yikes.
    I don't know how to bug report this, as I can't give steps to reproduce.

    Thought: Is anyone else using SVN Tools or some manner of version control? I wonder if that has anything to do with it. I'm also working in Visual Studio (Community 2015).
     
    Last edited: Aug 3, 2016
  23. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    @Pukami Can you send me your bug number, I would like to investigate this.

    Like @jwinn said it can happen when you modified a script and introduce a compiler error. As soon as you go back to Unity, mono will try to compile all scripts and since the script doesn't compile mono can't instanciate the class from the script so we end up with an null c# instance.
    The SMB inspector is build in a way to handle those case, when an instance become null we keep all the information necessary to know which script, controller, state/statemachine is affected,so when the user fix the compiler error we can recreate the invalid instance
     
  24. jwinn

    jwinn

    Joined:
    Sep 1, 2012
    Posts:
    88
    The problem remains after fixing the compiler errors. I hit play (0 errors or warnings) and notice the animator is broke again; go take a look in the Animator, and yep, StateMachineBehaviours are all null. Sounds like the bug resides somewhere in the recreation of the invalid instance- it's not happening in some cases.
     
    geff likes this.
  25. geff

    geff

    Joined:
    Mar 3, 2013
    Posts:
    28
    +1 Exact same problem here.

    All my StateMachineBehaviour are gone after a compiler error.
    After fixing the error, the StateMachineBehaviour are still missing.
     
  26. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    Had this happen again. I opened Unity with a compilation error, and had to reset the layout. There was an animator in the scene, and this is how it's controller looked directly after opening:

    Untitled.png

    Note the None (Mono Script).

    The git log showed two things; first of all the references to the SMBs had all been deleted (note three states with one script each, and three missing scripts:

    Untitled2.png

    In addition, the fields that used to reference those scripts now referenced ID:0:

    Untitled1.png

    (There's a third one missing not visible in the screenshot).

    Can't really reproduce this; it's not consistent that this happens when a script fails to compile, but that seems to be the trigger. Since sometime during 5.2 or 5.3, Unity changed how script reloading worked, and there's been so many bugs, every single one relating to the editor trying to reload data when scripts are not compiling.
     
    jwinn likes this.
  27. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    This just happened to me today and has happened several times in the past. All State Machine Behavior scripts have been removed from my current controller. Because the animator is so prone to corruption, I try to keep duplicates of my Animator Controller. But this time, It's been several weeks since my last corruption so I'll need to grab a backup and sift through an old controller to figure out where I need all of my State Machine Behavior scripts. I sure hope Unity gets this one fixed. I'm using the current release version of Unity 5.4 so 5.4 did not fix the problem.
     
  28. bhinjlk

    bhinjlk

    Joined:
    Dec 15, 2014
    Posts:
    10
    It happened me several times. I work on 5.1.4f1. The unique patch solution that I have found is using Git. When my state machine behaviours disappear I close unity, then I go to my GIT repository and download the file "*.controller" and "*.controller.meta". Finally, I copy and replace these files into my unity project and reopen Unity and all works well again.
     
  29. CaseyLee

    CaseyLee

    Joined:
    Jan 17, 2013
    Posts:
    41
    This is happening to me several times in the last week. I have been creating a lot of .asset files as I'm building a sort of db for editor purposes. currently on 5.5.0f3, I had this problem once before in 5.4.1f1but now that I am running
    AssetDatabase.ImportAsset and AssetDatabase.SaveAssets with some frequency - it seems to happen more often.

    It is a horrifying experience. and its not as if I'm importing an asset from outside my game and there-for prepared by having the project freshly backed-up. Also, The SMBs are only deleted from the controller I am currently working on.
     
  30. stefankohl

    stefankohl

    Joined:
    May 30, 2014
    Posts:
    53
    I have not experienced that problem for over a year now. However, I think it's a good idea to store assets as text instead of binary and use version control (in my case: git) to keep track of all changes made, similar to what bhinjlk suggested. Before committing your changes, you should go through all updated files and discard any unwanted modifications. I also do this when re-importing 3D models from the Asset Store to recover the changes I have made to the animation import settings.
     
  31. Travis-Goetz

    Travis-Goetz

    Joined:
    Feb 5, 2015
    Posts:
    7
    Any idea if this issue is going to be fixed soon?

    Running 5.5.0f3 and this happened yesterday. I opened Unity with compiler errors and got the same none/null script display screenshotted above, as all SMB scripts had been erased.

    Have not been able to repro it yet. This is a pretty severe bug for anyone attempting to use State Machine Behaviors or Mecanim as a FSM.
     
  32. sanmn19

    sanmn19

    Joined:
    Jun 30, 2013
    Posts:
    56
    5.4.1 to 5.5.0p4 caused this problem.
     
  33. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    We would like to fix this issue but nobody is able to provide a bug report with a repro step.
     
  34. CaseyLee

    CaseyLee

    Joined:
    Jan 17, 2013
    Posts:
    41
    After my above post, I went back and cleaned up a lot of my animation behavior scripts just on a whim – notably some of their custom Editor scripts needed an major overall. After I made those changes I haven't had any problems yet (Cross Fingers Knocks On Wood). Anyway here are some of the things I found in some of my early made State Machine Behavior scripts that I went back and changed.


    1. No longer declare SerializedPropertys at top of class, I was doing this so then I could Set references in OnEnable with a serializedObject.FindProperty call. Now I just declare all serialized properties as local variables and just use the FindProperty call on each onGui update.


    2. One of my older scripts (Example below). I had declared my target SerializedObject at top of class and only defined it in on enable and NOT in OnInspectorGUI. Additional I had a redundant reference to target. I believe I had copied this format from a tutorial on the internets somewhere... others may have seeing that and copied it like i did, It was several years back so I don't remember exactly where I got the format from.

    SMBCodeExample.png



    eh Ill edit post if I remember other stuff that I changed ... or if it crashes again so none of the above matters ;D
     
  35. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    Now, 2nd time for me, unity 5.5.0f3.

    This bug still exit. :(
     
  36. Malbers

    Malbers

    Joined:
    Aug 7, 2015
    Posts:
    2,558
    Still exist on 5.5.1 and 5.5.2 :(
     
  37. samnarain

    samnarain

    Joined:
    Jul 6, 2015
    Posts:
    99
    We would like to fix this issue but nobody is able to provide a bug report with a repro step.
    xD

    Anyway, I just encountered this bug in the latest 5.6.3p3, but it was fairly simple to reproduce and fix (work around). If you keep Animator window open for a while, and work within a sub state machine and back up the layer, adding the SMB, will simply make it vanish like it has been never added; surprisingly, it happens even when doing a "save scenes", and "save project" a second after.

    But for you good people out there, here is the simple workaround.

    1. First, close the Animator window, and find your Animation Controller asset in your project and click it to pop open Animator. The problem will still persist if you are experiencing this, just keep following me on.

    2. Find a reference (any will do, or create a dummy GameObject and add an animator with the controller). Deactivate it, which will mark the scene as "dirty" (showing the asterisk *). Save the scene, save the project.

    3. Add your behaviour to the controller as you normally would. Save your changes. You can now remove the dummy object if you created one, or activate your Animator component again on your existed one.

    4. Take a zip of your beer, because life will be good again.

    In case you didn't knew, the Animator is quite busted; when it comes to odd errors, most can be solved by doing this kind of work around. It won't solve the null pointers though, it will just prevent that added SMB's will disappear again. But, since you all are super into that great thing called source control, you have nothing to worry about; just reset back to the commit you knew was working like heaven - do the magic trick I've given you above, and you'll be fine.

    <3 (it's a heart)
     
    Malbers likes this.
  38. SEVENL

    SEVENL

    Joined:
    Apr 15, 2014
    Posts:
    5