Search Unity

Null transition in state 'AnyState'

Discussion in 'Animation' started by Griffo, Aug 3, 2015.

  1. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Hi,

    I removed a boolean from my animation controller now I get the massage "Null transition in state 'AnyState'"

    I've tried removing it by selecting it then pressing the minus sign but it will not remove, any ideas ?

    Thanks.

    Screen Shot 2015-08-03 at 17.31.51.png
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    have you try to switch your inspector mode from normal to debug, and remove the transition from there?
     
  3. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Sorry to sound a bit stupid but how would I do that, when I switch to debug the window above changes to ..

    Screen Shot 2015-08-03 at 18.40.48.png
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    yeah sorry, I mean debug-internal but you don't have access to this in a release build.

    Can you reproduce the bug?
     
  5. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    This happened once before and I had to rebuild the animation controller, but this one is larger and don't really want to rebuild it ...

    I'll try it on another controller and see if I can reproduce it.
     
  6. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  7. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Thank you, that will come in handy ..
     
  8. Splendorr

    Splendorr

    Joined:
    Aug 11, 2013
    Posts:
    2
    @Mecanim.Dev Can you elaborate on where to use this API code? We're seeing this same error, with dozens of "not found" transitions, but have never had to deal with this before. Thank you!

     
  9. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  10. Ghostbright

    Ghostbright

    Joined:
    Sep 6, 2014
    Posts:
    10
    @Mecanim.Dev Hey, Splendorr's on my team.

    I'm not sure how to re-create the bug, but it has been happening with almost all my new objects. The object from the screenshot above, however, is an old one. It use to have a lot of different animations for different characters. I deleted the animations and source sprites so that the object would only have three animations. As you can see, something remained.

    I'm currently attempting to wrap my head around writing an editor script. I see these parts here, but I'm not exactly sure how to use them. I have made a menu, and I would like for there to be an option that simply looks at each animator controller, finds the offending "Any State" machine, and removes the null transitions. The language is a little obscure here though, and I'm making slow progress. Could you please explain further what you have in mind?
     
    Last edited: Sep 4, 2015
  11. Ghostbright

    Ghostbright

    Joined:
    Sep 6, 2014
    Posts:
    10
    OK, I have gotten to the point where I can use script find each transition that reports "not found" and have tried removing them with DestroyImmediately. This does not get rid of them though.

    I have found "RemoveStateMachineTransition" but that function is looking for and "AnimatorTransition" whilst all I have is a "StateTransition." Is there any way to get the animator transition from a state transition? Am I going about this wrong?
     
    Last edited: Sep 4, 2015
  12. Ghostbright

    Ghostbright

    Joined:
    Sep 6, 2014
    Posts:
    10
    OK, I got it working using the following code:


    Code (CSharp):
    1. [MenuItem("SkeleTab/CleanAnCons")]  
    2.     static void CleanAnCons()
    3.     {
    4.         if(Selection.activeObject.GetType() == typeof(AnimatorController))
    5.         {
    6.             AnimatorController aniCon = (AnimatorController)Selection.activeObject;
    7.  
    8.             AnimatorStateMachine aniMec = aniCon.layers[0].stateMachine;
    9.  
    10.             AnimatorStateTransition[] alStates = aniCon.layers[0].stateMachine.anyStateTransitions;
    11.  
    12.             foreach(AnimatorStateTransition state in alStates)
    13.             {
    14.                 if(state == null)
    15.                 {
    16.                     Debug.Log("Found one!");
    17.  
    18.                     aniMec.RemoveAnyStateTransition(state);
    19.                 }
    20.             }
    21.         }
    22.     }
    Any glaring problems in there?

    Also, just out of curiosity, would there be a way of deleting similar transitions were they to be coming from a state machine other than "Any State"? As far as I know, this is not the case, I would just like to know in case that becomes useful in the future.
     
  13. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    no it's perfect, just don't forget to loop over all your layer if you have more than one.

    Yes, state transition are located on state
    http://docs.unity3d.com/ScriptReference/Animations.AnimatorState-transitions.html
    In this case you need to iterate over all AnimatorState one by one
     
  14. Splendorr

    Splendorr

    Joined:
    Aug 11, 2013
    Posts:
    2
    @Mecanim.Dev Thank you so much for your help! You got us going in the right direction. :)
     
  15. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    This seems to happen at times when you delete a state which has transitions into it. Usually the transition is deleted, but not always.

    I've found that going into the controller file with notepad++ and deleting the transition is the easiest way to deal with it. Each state has a field named m_Transitions, with one line for each attached transition. It looks like this:

    Code (csharp):
    1. //three transitions:
    2.  
    3. m_Transitions:
    4.   - {fileID: 110149706}
    5.   - {fileID: 110124928}
    6.   - {fileID: 110197184}
    7.  
    8. //one transition:
    9.  
    10. m_Transitions:
    11.   - {fileID: 110185784}
    12.  
    13. //no transitions:
    14. m_Transitions: []
    If there's a null transition, it looks like this:

    Code (csharp):
    1. m_Transitions:
    2.   - {fileID: 0}
    So you can simply delete that line to remove the transition.

    I'll make a humble suggestion: you should be able to remove null states. They're listed in the list of transitions, but clicking the "-" button just doesn't do anything.
     
    Griffo and Splendorr like this.
  16. Darath_Infinigon

    Darath_Infinigon

    Joined:
    Jan 22, 2015
    Posts:
    4
    Hi,
    We had the same problem and as the code mentioned in this post is not working in Unity5 im leaving the script updated.
    This script will fix all the errors of the selected Animation controller.

    Code (CSharp):
    1. public class CleanNullReferenceAnimation: MonoBehaviour{
    2.  
    3.     [MenuItem("Tools/CleanSelectedNullReferenceAnimationController")]
    4.     private static void cleanAnimController(){
    5.         UnityEditor.Animations.AnimatorController ac = Selection.activeObject as UnityEditor.Animations.AnimatorController;
    6.         foreach(var layer in ac.layers){
    7.             foreach(var transition in layer.stateMachine.anyStateTransitions){
    8.                 if (transition == null){
    9.                         Debug.LogError("NULL STATE FOUND AND FIXED");
    10.                         layer.stateMachine.RemoveAnyStateTransition(transition);
    11.                      
    12.                     }
    13.  
    14.                 }
    15.  
    16.         }
    17.     }
    18. }