I have a big enum list exposed in the inspector on one of my prefab.
Scrolling through the enum list in the inspector is quite a long and fastidious process (click on the small arrow at the bottom of the list and wait to reach the correct value).
So I decided to create a custom script that can assign the enum value to any selected object by entering a string. The tool works to assign the value (the enum list is updated correctly). But, unfortunately, when I play in the editor, the value resets to the last value that was set manually. It seems that using my custom script to assign the enum value doesn’t work.
So my question is the following:
Can we speed up the scrolling through the enum list (Does the wheel work for most of you? It doesn’t for me for the enum list).
OR
How can I make sure that when I change an enum value through a custom script, it gets saved in the editor.
It is part of a custom tool used in an editor window.
So yes it’s an editor script.
I am changing the value on the prefab itself in the scene (not at run time - just to be clear)
I select it, press a button and it assigns the value.
I don’t call Update … (Actually… I am not sure what you are talking about )
Thanks for your help, it works. It was not that simple for me but I found out how to make it work.
I am posting part of the code I use to change my enum, in case someone wants to take a look.
enumToEnter = GUILayout.TextArea(enumToEnter);
string tmpEnumName;
if(GUILayout.Button("Assign EnumTo Trap to Selection")){
if(enumToEnter != ""){
GameObject go = Selection.activeGameObject;
SerializedObject so = new SerializedObject(go.GetComponent<LevelTransition>());
if(go != null){
for(int x=0;x< Enum.GetValues(typeof(LevelTransition.LevelTransitionTo)).Length;x++){
tmpEnumName = Enum.GetName(typeof(LevelTransition.LevelTransitionTo), x);
if( tmpEnumName.Contains("TrapHole" + enumToEnter + "a")){
so.FindProperty("levelTransitionTo").enumValueIndex = x+1;
so.FindProperty("levelTransitionFrom").enumValueIndex = x;
so.ApplyModifiedProperties();
Debug.LogWarning("Trap is updated!");
break;
}
}
}
else
Debug.LogError("Please select an object");
}
else
Debug.LogError("There is no enumToEnter entered in the field.");
}