ArgumentException: Getting control 3's position in a ...

Getting this error (

) on this line of code know why???

GUILayout.Label ("Turning Ability");

yeah I know it isn’t good enough for help so here is the entire script part (ON.GUI atleast)

DO NOT correct me on other parts because this is how I got this error when you guys corrected me on this script!

Edit: Sorry for the big script for this is the ship creation mode, such as with the customize car options in midnightclub 4

105100–4027–$jetparts_319.js (20.7 KB)

here is the code around it as in the code that is next to it.

GUILayout.Label("Money: " + money.ToString());
	GUILayout.Label("Cost of Parts: " + cost.ToString());
	GUILayout.Label ("Jet Stats");
	GUILayout.Label ("Turning Ability");
	GUILayout.Label (turning.ToString());
	GUILayout.Label ("Strength (How Much Damage The Ship Can Take)");
	GUILayout.Label (strength.ToString());
	GUILayout.Label ("Speed (How Fast The Ship Is)");
	GUILayout.Label (speed.ToString());
	GUILayout.Label ("Tricks (How fast The Ship can Preform Tricks)");
	GUILayout.Label (tricks.ToString());

I am getting this mysterious error message too, and I believe it’s a bug:

http://forum.unity3d.com/viewtopic.php?t=9439

It seems the way to solve it (if you can) is to use GUI instead of GUILayout…

You get this message if the flow of your codechanges within the same frame Without the user doing something in the GUI.

E.g: this will always result in an error:

var a = false;
function OnGUI () {
    a = Random.value < .5;
    if (a)
        GUILayout.Button ("ADFS");
}

Whereas this will work:

var a;

function OnGUI () {
    if (GUILayout.Button ("Randomize"))
        a = Random.value < .5;
    if (a)
        GUILayout.Button ("ADFS");
}

Ah! Thanks so much for the reply. I’ll assume this is actually a bug, but a bug with a fix?

Anyway, yay fixed my problem now! 8)

How is it a bug when its stated “don’t do this” and bad things happen when you do it anyway?

Well, the bug is in the code that does this funky stuff, so it’s obviously not a Unity bug. Not that it never happened to me - but when you get more of an understanding of how UnityGUI works, it happens less frequently :wink:

I guess one key to understand this is that OnGUI() is called a couple of times, with different purposes. You can check why it is called via Event.current. Not perfectly sure, but I think the first time it is called in:

EventType.Layout

So … anything that changes the layout of your GUI must have been done before that, and you should not change the layout afterwards (unless, maybe through UnityGUI-related user actions). If you look at the documentation of EventType, you’ll find a few other noteworthy events like Repaint.

Ok, perhaps ‘bug’ isn’t the right word for it… because OnGUI is working the way it was intended. Also I can’t seem to find it AngryAnt, where in the documentation is it stated ‘dont do this’?

I still feel this issue needs addressing… It might be as simple as the fact that the Error message is completely unhelpful in terms of working out what’s going on…

It needs to explicitly say “You’ve changed a variable in OnGUI without the user’s input” or something… not just output a mystical message about ‘groups’.

Thanks for the help guys :slight_smile:

You don’t know how grateful I am to you sir, Thanks, Thanks, Thanks. That solved the problem Like a charm, alghough my soloution was to check do this on top of the method onGui:

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
    if (Event.current.type != EventType.Repaint)
        return;
    //
   ///
}