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.
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.
have you try to switch your inspector mode from normal to debug, and remove the transition from there?
Sorry to sound a bit stupid but how would I do that, when I switch to debug the window above changes to …
yeah sorry, I mean debug-internal but you don’t have access to this in a release build.
Can you reproduce the bug?
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.
If you can write script you can use the API to remove this null transition.
controller.layers[0].stateMachine.anyStateTransitions;
Thank you, that will come in handy …
@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!
Hi splendorr,
You seem to have a lot of null transition, do you know how to reproduce this bug?
You need to write a editor script, this script should find all your controller and for each statemachine in your controllers you will need to remove all the anyStateTransitions that are null.
Take a look at Unity - Scripting API: MenuItem
and Unity - Manual: Special folder names section Editor
to write your editor script
@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?
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?
OK, I got it working using the following code:
[MenuItem("SkeleTab/CleanAnCons")]
static void CleanAnCons()
{
if(Selection.activeObject.GetType() == typeof(AnimatorController))
{
AnimatorController aniCon = (AnimatorController)Selection.activeObject;
AnimatorStateMachine aniMec = aniCon.layers[0].stateMachine;
AnimatorStateTransition[] alStates = aniCon.layers[0].stateMachine.anyStateTransitions;
foreach(AnimatorStateTransition state in alStates)
{
if(state == null)
{
Debug.Log("Found one!");
aniMec.RemoveAnyStateTransition(state);
}
}
}
}
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.
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
@Mecanim-Dev Thank you so much for your help! You got us going in the right direction. ![]()
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:
//three transitions:
m_Transitions:
- {fileID: 110149706}
- {fileID: 110124928}
- {fileID: 110197184}
//one transition:
m_Transitions:
- {fileID: 110185784}
//no transitions:
m_Transitions: []
If there’s a null transition, it looks like this:
m_Transitions:
- {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.
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.
public class CleanNullReferenceAnimation: MonoBehaviour{
[MenuItem("Tools/CleanSelectedNullReferenceAnimationController")]
private static void cleanAnimController(){
UnityEditor.Animations.AnimatorController ac = Selection.activeObject as UnityEditor.Animations.AnimatorController;
foreach(var layer in ac.layers){
foreach(var transition in layer.stateMachine.anyStateTransitions){
if (transition == null){
Debug.LogError("NULL STATE FOUND AND FIXED");
layer.stateMachine.RemoveAnyStateTransition(transition);
}
}
}
}
}