Editor script IntField won't hold value

I have an issue with values entered in an EditorGUILayout.IntField getting reset when the control loses focus or ‘enter’ is pressed.

From the example here:

the value assigned in this line:

sizeMultiplier = EditorGUILayout.IntField("Number of clones:", clones);

gets reset when clicking off of the edit box control or clicking the button, so you always only get one copy.

Am I missing something obvious or is this a Unity issue?

Unity 2020.2.1 / Windows 10 20H2

The traditional use of IntField() is to pass the same variable in that you assign back out… that’s the point.

So instead of this:

sizeMultiplier = EditorGUILayout.IntField("Number of clones:", clones);

You would want:

clones = EditorGUILayout.IntField("Number of clones:", clones);
1 Like