Search Unity

Editor script IntField won't hold value

Discussion in 'Editor & General Support' started by SentientSkull, Dec 27, 2020.

  1. SentientSkull

    SentientSkull

    Joined:
    Apr 26, 2013
    Posts:
    75
    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:

    https://docs.unity3d.com/2020.2/Documentation/ScriptReference/EditorGUILayout.IntField.html

    the value assigned in this line:

    Code (CSharp):
    1. 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
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    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:

    Code (csharp):
    1. sizeMultiplier = EditorGUILayout.IntField("Number of clones:", clones);
    You would want:

    Code (csharp):
    1. clones = EditorGUILayout.IntField("Number of clones:", clones);
     
    SentientSkull likes this.