Strange error when calling WWW within a GUI element?

ArgumentException: Getting control 0’s
position in a group with only 0
controls when doing Repaint

Aborting

Say what?! huh?

Been trying to figure out what this control 0 is or why my GUI suddently should be empty?

I have a HUGE switch(state) thing going on in my GUI so that I dont waste a lot of IF… THEN structures on testing all the time.

And it works like a charm. Until now.

Reason is that I call a “storage script” that uses WWWFORM and WWW to send my data to the webserver while it also switches state so that the GUI will say: “saving…” while we wait for the WWW to return a flag.

The state machine works perfectly (I think) as everything but the actual update when the data returns runs.

But I cant find any documentation on error codes? anyone familiar with this one?

I use GUILayout for all my states, thats any help. I’ll post some code if neccesary, but I think the best solution for me would be if someone can explain what the error is about.

Then I will be able to track down the problem.

Note. I have triplechecked that I dont have too many or to few Begin/End Area/view etc. I’ve even moved the saving state outside the GUI to see if that would remove my error. But no luck.

The faulty state is the primary state that runs from start. It works perfectly until I press “save”. Infact the GUI keeps running, so its not a fatal error?

2 Answers

2

That’s what you should avoid state changing events in OnGUI. The problem is that OnGUI is always called twice. It performs a layouting call where Unity writes all elements you “draw” into a temporary list and after that step Unity can distribute the width / height to the elements. In the second repaint call the actual drawing and logic processing is performed. If you change the “things” you draw between those two calls the internal list will not match with the elements you want to draw…

btw, some code would help to spot the point where the elements are scrambled ;)

Perfect explanation, I am sure this is why then. Only thought OnGui was called once. Dang! what a strange behaviour.

Here is a forum thread to this topic.