I recently updated my Unity version to 2019.3.15f1 . I opened a project which was created in the 2017 version of unity. My problem is that after upgrading to the new version, when I click on a state in the animator controller the state sometimes does not show in the inspector. But that’s not all. Some states do show in the inspector when clicked some do not.
For example I had a script on a statemachine that handles multiple animations. The script also does not show when I click on the statemachine.
I don’t know if I am missing something obvious, or if it actually is a problem created by switching the version.
So this is an issue they are aware of:
The work around is to “Open the Animator file in a Text Editor and change the ‘m_ObjectHideFlags’ properties for the affected states from ‘3’ to ‘1’”
punk
July 27, 2020, 6:59am
6
Thanks @NapsTeam Lifesaver! I updated your script to deal with Sub Statemachines and BlendTree’s also
using UnityEditor;
using UnityEngine;
public class AnimUnhideTool : ScriptableObject
{
[MenuItem("Assets/Unhide Fix")]
private static void unhide()
{
UnityEditor.Animations.AnimatorController ac = Selection.activeObject as UnityEditor.Animations.AnimatorController;
foreach (UnityEditor.Animations.AnimatorControllerLayer layer in ac.layers)
{
foreach (UnityEditor.Animations.ChildAnimatorState curState in layer.stateMachine.states)
{
if (curState.state.hideFlags != 0) curState.state.hideFlags = (HideFlags)1;
if (curState.state.motion != null)
{
if (curState.state.motion.hideFlags != 0) curState.state.motion.hideFlags = (HideFlags)1;
}
}
foreach (UnityEditor.Animations.ChildAnimatorStateMachine curStateMachine in layer.stateMachine.stateMachines)
{
foreach (UnityEditor.Animations.ChildAnimatorState curState in curStateMachine.stateMachine.states)
{
if (curState.state.hideFlags != 0) curState.state.hideFlags = (HideFlags)1;
if (curState.state.motion != null)
{
if (curState.state.motion.hideFlags != 0) curState.state.motion.hideFlags = (HideFlags)1;
}
}
}
}
EditorUtility.SetDirty(ac);
}
}
Multiple fixer:
using UnityEditor;
using UnityEngine;
public class AnimUnhideTool : ScriptableObject
{
[MenuItem("Tools/Animator States Unhide Fix")]
private static void Fix()
{
if (Selection.objects.Length < 1) throw new UnityException("Select animator controller(s) before try fix it!");
int scnt = 0;
foreach (Object o in Selection.objects)
{
UnityEditor.Animations.AnimatorController ac = o as UnityEditor.Animations.AnimatorController;
if (ac == null) continue;
foreach (UnityEditor.Animations.AnimatorControllerLayer layer in ac.layers)
{
foreach (UnityEditor.Animations.ChildAnimatorState curState in layer.stateMachine.states)
{
if (curState.state.hideFlags != 0)
{
curState.state.hideFlags = (HideFlags)1;
scnt++;
}
if (curState.state.motion != null)
{
if (curState.state.motion.hideFlags != 0) curState.state.motion.hideFlags = (HideFlags)1;
}
}
foreach (UnityEditor.Animations.ChildAnimatorStateMachine curStateMachine in layer.stateMachine.stateMachines)
{
foreach (UnityEditor.Animations.ChildAnimatorState curState in curStateMachine.stateMachine.states)
{
if (curState.state.hideFlags != 0)
{
curState.state.hideFlags = (HideFlags)1;
scnt++;
}
if (curState.state.motion != null)
{
if (curState.state.motion.hideFlags != 0) curState.state.motion.hideFlags = (HideFlags)1;
}
}
}
}
EditorUtility.SetDirty(ac);
}
Debug.Log("Fixing " + scnt + " states done!");
}
}
I also am having this issue in my project after upgrading to 2019.3.15f1. I think this could be a bug. I made a copy of my project and tried opening it in 2020.1.0b10 with the same result. I just hope that the animator controllers weren’t corrupted by 2019.3.15f1. Has anyone filed a bug report?
reigota
September 2, 2020, 8:03pm
8
A bit more complete and recursive solution, based on previous answers:
using UnityEditor;
using UnityEngine;
public class AnimUnhideTool
{
[MenuItem("Tools/Animator States Unhide Fix")]
private static void Fix()
{
if (Selection.objects.Length < 1)
throw new UnityException("Select animator controller(s) before try fix it!");
int scnt = 0;
foreach (Object o in Selection.objects)
{
UnityEditor.Animations.AnimatorController ac = o as UnityEditor.Animations.AnimatorController;
if (ac == null)
continue;
foreach (UnityEditor.Animations.AnimatorControllerLayer layer in ac.layers)
{
foreach (UnityEditor.Animations.ChildAnimatorState curState in layer.stateMachine.states)
{
scnt = FixState(scnt, curState);
}
scnt = FixStateMachines(scnt, layer.stateMachine.stateMachines);
}
EditorUtility.SetDirty(ac);
}
Debug.Log("Fixing " + scnt + " states done!");
}
private static int FixStateMachines(int scnt, UnityEditor.Animations.ChildAnimatorStateMachine[] stateMachines)
{
foreach (UnityEditor.Animations.ChildAnimatorStateMachine curStateMachine in stateMachines)
{
if (curStateMachine.stateMachine.hideFlags != (HideFlags)1)
{
curStateMachine.stateMachine.hideFlags = (HideFlags)1;
}
if (curStateMachine.stateMachine.stateMachines != null)
{
scnt = FixStateMachines(scnt, curStateMachine.stateMachine.stateMachines);
}
if (curStateMachine.stateMachine.entryTransitions != null)
{
foreach (UnityEditor.Animations.AnimatorTransition curTrans in curStateMachine.stateMachine.entryTransitions)
{
if (curTrans.hideFlags != (HideFlags)1)
{
curTrans.hideFlags = (HideFlags)1;
}
}
}
foreach (UnityEditor.Animations.ChildAnimatorState curState in curStateMachine.stateMachine.states)
{
scnt = FixState(scnt, curState);
}
}
return scnt;
}
private static int FixState(int scnt, UnityEditor.Animations.ChildAnimatorState curState)
{
if (curState.state.hideFlags != (HideFlags)1)
{
curState.state.hideFlags = (HideFlags)1;
scnt++;
}
if (curState.state.motion != null)
{
if (curState.state.motion.hideFlags != (HideFlags)1)
curState.state.motion.hideFlags = (HideFlags)1;
}
if (curState.state.transitions != null)
{
foreach (UnityEditor.Animations.AnimatorStateTransition curTrans in curState.state.transitions)
{
if (curTrans.hideFlags != (HideFlags)1)
{
curTrans.hideFlags = (HideFlags)1;
}
}
}
if (curState.state.behaviours != null)
{
foreach (StateMachineBehaviour behaviour in curState.state.behaviours)
{
if (behaviour.hideFlags != (HideFlags)1)
behaviour.hideFlags = (HideFlags)1;
}
}
return scnt;
}
}
reigota answer that Includes animator transitions:
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;
public class AnimUnhideTool
{
[MenuItem("Tools/Animator States Unhide Fix")]
private static void Fix()
{
if (Selection.objects.Length < 1)
throw new UnityException("Select animator controller(s) before try fix it!");
int scnt = 0;
foreach (Object o in Selection.objects)
{
AnimatorController ac = o as AnimatorController;
if (ac == null)
continue;
foreach (AnimatorControllerLayer layer in ac.layers)
{
foreach (ChildAnimatorState curState in layer.stateMachine.states)
{
scnt = FixState(scnt, curState);
}
scnt = FixStateMachines(scnt, layer.stateMachine, layer.stateMachine.stateMachines);
}
EditorUtility.SetDirty(ac);
}
Debug.Log("Fixing " + scnt + " states done!");
}
private static int FixStateMachines(int scnt, AnimatorStateMachine parent, ChildAnimatorStateMachine[] stateMachines)
{
foreach (ChildAnimatorStateMachine curStateMachine in stateMachines)
{
foreach (var trans in parent.GetStateMachineTransitions(curStateMachine.stateMachine))
{
trans.hideFlags = (HideFlags)1;
scnt++;
}
if (curStateMachine.stateMachine.hideFlags != (HideFlags)1)
{
curStateMachine.stateMachine.hideFlags = (HideFlags)1;
}
if (curStateMachine.stateMachine.stateMachines != null)
{
scnt = FixStateMachines(scnt, curStateMachine.stateMachine, curStateMachine.stateMachine.stateMachines);
}
if (curStateMachine.stateMachine.entryTransitions != null)
{
foreach (AnimatorTransition curTrans in curStateMachine.stateMachine.entryTransitions)
{
curTrans.hideFlags = (HideFlags)1;
}
}
foreach (ChildAnimatorState curState in curStateMachine.stateMachine.states)
{
scnt = FixState(scnt, curState);
}
}
return scnt;
}
private static int FixState(int scnt, ChildAnimatorState curState)
{
if (curState.state.hideFlags != (HideFlags)1)
{
curState.state.hideFlags = (HideFlags)1;
scnt++;
}
if (curState.state.motion != null)
{
curState.state.motion.hideFlags = (HideFlags)1;
}
if (curState.state.transitions != null)
{
foreach (AnimatorStateTransition curTrans in curState.state.transitions)
{
curTrans.hideFlags = (HideFlags)1;
}
}
if (curState.state.behaviours != null)
{
foreach (StateMachineBehaviour behaviour in curState.state.behaviours)
{
behaviour.hideFlags = (HideFlags)1;
}
}
return scnt;
}
}
I’m having the same problem. All the duplicate states in the animation controller have blank inspectors. This affects all the duplicated states that were created before the update as well.
You can try this script we used as workaround for now
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Animations;
using UnityEditor;
using UnityEditor.Animations;
public class AnimUnhideTool : ScriptableObject
{
[MenuItem("Assets/Unhide Fix")]
private static void unhide()
{
UnityEditor.Animations.AnimatorController ac = Selection.activeObject as UnityEditor.Animations.AnimatorController;
foreach (UnityEditor.Animations.AnimatorControllerLayer layer in ac.layers)
{
foreach (UnityEditor.Animations.ChildAnimatorState curState in layer.stateMachine.states)
{
if (curState.state.hideFlags!=0) curState.state.hideFlags = (HideFlags)1;
}
}
EditorUtility.SetDirty(ac);
}
}
chaneya
November 18, 2020, 11:03pm
10
The above scripts do not fix the problem if you are using duplicate statemachinebehavior scripts/components on your animator states. Any duplicate statemachinebehaviors on your animator states remain hidden from view after using the AnimUnHideTool scripts. And the stateMachineBehaviors do not run if they are hidden in the inspector. Additionally, you cannot add duplicates of the same statemachinebehavior script to a state. I’m using Unity 2020.1.12 and 2020.1.13.
joe_ftg
September 4, 2021, 8:50pm
11
Modifications to the previous scripts to handle blend trees with children
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;
//from https://answers.unity.com/questions/1736606/animation-state-of-controller-not-showing-in-inspe.html?page=2
public class AnimUnhideTool
{
[MenuItem( "Tools/Animator States Unhide Fix" )]
private static void Fix()
{
string errorMsg = "";
if ( Selection.objects.Length < 1 )
{
errorMsg += "Select animator controller(s) before starting the operation!";
}
else
{
bool controllerFound = false;
int issuesFixedCounter = 0;
foreach ( Object o in Selection.objects )
{
AnimatorController ac = o as AnimatorController;
if ( ac == null )
continue;
controllerFound = true;
foreach ( AnimatorControllerLayer layer in ac.layers )
{
foreach ( ChildAnimatorState curState in layer.stateMachine.states )
{
issuesFixedCounter = FixState( issuesFixedCounter, curState );
}
issuesFixedCounter = FixStateMachines( issuesFixedCounter, layer.stateMachine, layer.stateMachine.stateMachines );
}
EditorUtility.SetDirty( ac );
}
if ( !controllerFound )
{
errorMsg += "Select animator controller(s) before starting the operation!";
}
else
{
errorMsg += "Fixed " + issuesFixedCounter + " issues!";
}
}
if ( errorMsg.Length > 0 )
{
EditorUtility.DisplayDialog( "Finished", errorMsg, "Ok" );
}
}
private static int FixStateMachines( int issuesFixedCounter, AnimatorStateMachine parent, ChildAnimatorStateMachine[] stateMachines )
{
if ( stateMachines != null )
{
foreach ( ChildAnimatorStateMachine curStateMachine in stateMachines )
{
if ( curStateMachine.stateMachine.hideFlags != (HideFlags)1 )
{
curStateMachine.stateMachine.hideFlags = (HideFlags)1;
issuesFixedCounter++;
}
issuesFixedCounter = FixStateMachineBehaviours( issuesFixedCounter, curStateMachine.stateMachine.behaviours );
issuesFixedCounter = FixStateMachines( issuesFixedCounter, curStateMachine.stateMachine, curStateMachine.stateMachine.stateMachines );
issuesFixedCounter = FixAnimatorTransitions( issuesFixedCounter, parent.GetStateMachineTransitions( curStateMachine.stateMachine ) );
issuesFixedCounter = FixAnimatorTransitions( issuesFixedCounter, curStateMachine.stateMachine.entryTransitions );
foreach ( ChildAnimatorState curState in curStateMachine.stateMachine.states )
{
issuesFixedCounter = FixState( issuesFixedCounter, curState );
}
}
}
return issuesFixedCounter;
}
private static int FixState( int issuesFixedCounter, ChildAnimatorState curState )
{
if ( curState.state.hideFlags != (HideFlags)1 )
{
curState.state.hideFlags = (HideFlags)1;
issuesFixedCounter++;
}
issuesFixedCounter = FixMotion( issuesFixedCounter, curState.state.motion );
issuesFixedCounter = FixStateTransitions( issuesFixedCounter, curState.state.transitions );
issuesFixedCounter = FixStateMachineBehaviours( issuesFixedCounter, curState.state.behaviours );
return issuesFixedCounter;
}
private static int FixAnimatorTransitions( int issuesFixedCounter, AnimatorTransition[] transitions )
{
if ( transitions != null )
{
foreach ( AnimatorTransition curTrans in transitions )
{
if ( curTrans.hideFlags != (HideFlags)1 )
{
curTrans.hideFlags = (HideFlags)1;
issuesFixedCounter++;
}
}
}
return issuesFixedCounter;
}
private static int FixStateTransitions( int issuesFixedCounter, AnimatorStateTransition[] transitions )
{
if ( transitions != null )
{
foreach ( AnimatorStateTransition curTrans in transitions )
{
if ( curTrans.hideFlags != (HideFlags)1 )
{
curTrans.hideFlags = (HideFlags)1;
issuesFixedCounter++;
}
}
}
return issuesFixedCounter;
}
private static int FixStateMachineBehaviours( int issuesFixedCounter, StateMachineBehaviour[] behaviours )
{
if ( behaviours != null )
{
foreach ( StateMachineBehaviour behaviour in behaviours )
{
if ( behaviour.hideFlags != (HideFlags)1 )
{
behaviour.hideFlags = (HideFlags)1;
issuesFixedCounter++;
}
}
}
return issuesFixedCounter;
}
private static int FixMotion( int issuesFixedCounter, Motion motion )
{
if ( motion != null )
{
if ( motion.hideFlags != (HideFlags)1 )
{
motion.hideFlags = (HideFlags)1;
issuesFixedCounter++;
}
BlendTree blendTree = motion as BlendTree;
if ( blendTree != null )
{
ChildMotion[] childMotions = blendTree.children;
if ( childMotions != null )
{
foreach ( ChildMotion childMotion in childMotions )
{
issuesFixedCounter = FixMotion( issuesFixedCounter, childMotion.motion );
}
}
}
}
return issuesFixedCounter;
}
}