Yes, similar fields in EditorGUI return the value entered by the user.
Logically, everything is simple to understand: in order to set the value to a field, it is enough for it to transfer some value from a variable or write it manually. However, in this case, in fact, this field will be read-only , because through the inspector, the value in this field cannot be changed in any way. Which is logical, because OnGUI works several times a second, and in the field we can write EditorGUILayout.IntField("Number of clones:", 100500); , as a result, a field with a constant value is redrawn several times a second.
Why write like this: clones = EditorGUILayout.IntField("Number of clones:", clones); ? To make, so to speak, the message between the variable and the value that the user entered. It turns out a certain infinite circle:
- The value of the variable is entered in the field.
- User changes field value
- This value is passed back to the variable to:
- After the next update of
OnGUI value of this variable is again in the IntField Thus, we can influence the variable through the field. A field to display the actual value of the variable at the moment
If you do not want the value to be variable through the field changed, just write EditorGUILayout.IntField("Number of clones:", clones); without clones =
It may seem logical question, why not make the transfer of the link? But not all values are written that way. Some do not return a value to a variable, so that the field remains just read-only and at the same time the value of the variable cannot be changed through the field.
It may seem that developers would be more logical to do something like that EditorGUILayout.IntField("Number of clones:", clones, true/false); where true / false sets to pass by value to a link or not, but I think it’s harder logically to implement than just returning a value. Perhaps even for some reason.