- Home /
EditorGUILayout.EnumPopup giving me errors
Every single thing I've tried failed. I have a class called CrabScript>
public enum SpecialAbilities{Sleeper,Teleporter};
public SpecialAbilities SpecialAbility;
That's a declaration inside it. I made an editor for it which works fine for the other variable. For some reason, It's not working when I tried adding an enumpopup for the SpecialAbility variable.
crabScript.SpecialAbility = (crabScript.SpecialAbilities)EditorGUILayout.EnumPopup("Special Ability",crabScript.SpecialAbility);
That gives me the error: CrabScriptEditor.crabScript is a field but a type is expected.
crabScript.SpecialAbility = EditorGUILayout.EnumPopup("Special Ability",crabScript.SpecialAbility) as SpecialAbilities;
Above code gives me the error: The type or namespace name `SpecialAbilities' could not be found. Are you missing a using directive or an assembly reference?
I tried doing using CrabScript; but of course that doesn't work either. The reason I did (crabScript.SpecialAbilities) instead of just SpecialAbilities in the first one is because it didn't have a variable for SpecialAbilities. Even if I use crabScript.SpecialAbilities the SpecialAbilities enum doesn't show up, I had to manually typed it in. Doing (typeof(crabScript.SpecialAbilities)) also doesn't work.
I didn't know it was going to be this difficult to simply add an EnumPopup.
Answer by Paparakas · Nov 09, 2013 at 11:31 AM
Got it to work by doing
crabScript.SpecialAbility = (CrabScript.SpecialAbilities)EditorGUILayout.EnumPopup("Special Ability",crabScript.SpecialAbility);
I guess the cast had to be the class.enum instead of instanceofclass.enum
Your enum is a local type declared inside your class. So when ever you want to use the enum type outside of the class you have to use the class name as prefix. You can never index a type from a reference to an object.
@Bunny83 That makes sense, I won't make the same mistake again.