- Home /
Question by
TheFuzzyketchup · Nov 20, 2015 at 11:31 AM ·
c#editoreditorguipopup
EditorGUI.Popup Use of unnasigned local variable
I've got a simpe EditorGUI.Popup set up in my editor, but I can't seem to find a way to assign the variable correctly.
string[] formOptions = new string[]
{
"Creature","Spell","Trap"
};
int formSelection = EditorGUI.Popup(new Rect(position.x, position.y + 20,
position.width * 0.9f, EditorGUIUtility.singleLineHeight),
"Type of Card:", formSelection , formOptions);
The formSelection is throwing a Use of unnasigned local variable and if I make another variable to replace formSelection with, the Popup won't change my selection.
I'm sure it's not a very complicated issue, but I can't find the information in C# anywhere, only JavaScript which I'd rather not delve into.
Comment
Best Answer
Answer by frarees · Nov 26, 2015 at 11:08 AM
Save your formSelection
as an instance field on your class.
int m_FormSelection;
...
void OnGUI ()
{
...
m_FormSelection = EditorGUI.Popup(new Rect(position.x, position.y + 20,
position.width * 0.9f, EditorGUIUtility.singleLineHeight),
"Type of Card:", m_FormSelection, formOptions);
...
}