MissingMethodException: Method not found: 'GUI.Label'.

I have a weird problem here is my script:

function OnGUI () {
    GUI.Label(Rect (10, 10, 100, 20), "Hello World!");
}

and it doesnt work.

Which is the new method to draw text?

why don’t you debug your script ? It should be the first step in your troubleshooting and should reveal something

The script is working properly. :smile: Read here. Unity - Scripting API: GUI.Label

There’s no change in the Documentation. And i have tested your codes on Unity 3.4

Call your script something other than “GUI”.

–Eric

Thank You it worked :wink:

Wow I have the same problem yes my script is not called GUI or anything even related to GUI but I keep getting this error :frowning:

This is the code:

var numPlayers: int = 0;
	
if (playerNumber.length > 0) {
	for (var l: int = 0; l < playerNumber.length; l++) {
		numPlayers++;
		GUI.Label(Rect(40,200,300,20), "Positions");
		GUI.Label(Rect(40,230+(numPlayers*20),300,20), playerNumber[l]);
	}
}

Any clues why?

the question is not if this script is called gui but if you by error named any script guy. scripts / classes must never have the same name as unity engine classes, because if you do you can no longer call GUI.XXX but need to use UnityEngine.GUI.XXX to call it with its full unique name

No sir we do not have any script or class or any such thing named as GUI or anything related to any Unity Engine Class, but just in case, to make sure I tried UnityEngine.GUI.Label as well right now but still the same thing, all our other GUI.Label calls work fine but as soon as it gets to this one it throws out that Missing Method Exception error, haven’t the foggiest why :frowning:

FYI: Restarting Unity sometimes seems to fix these weird errors right so I tried that as well but no luck again though.

Unity rarely has wierd errors…
Can you post the whole script ?

Well it is 467 lines long lol but here it is :slight_smile:
__ __Removed__ __

Not much experience with Unity yet, but isn’t this problematic

UnityEngine.GUI.Label(Rect(40,230+(numPlayers*20),300,20), playerNumber[l]);

playerNumber is an array of PlayerPositionData type. Is GUI.Label smart enough to know what to print out there?

I don’t think thats a problem but to make sure you could cast them to strings.
the script is way to big to debug like this so you will have to brake it up in parts and try to figure it out.

It’s not related to the error but I just wanted to point out that your numPlayers variable is redundant in that scenario.

Aoon, no you’re right, Unity is not smart enough to print each element of the array a line after the other on to the GUI, hence why I have the numPlayers variable which increases the Y value of the GUI.Label each time the loop passes through the statement, i.e. making each elemnt of the array to be printed on a separate line on GUI :slight_smile:

Appels yeah it is big, what exactly did you mean by to cast them to strings? Sorry I’ve had a long day, not really thinking straight.

KelsoMRK, could you please explain why it is redundant, I’ve done the same thing before with other arrays it has so far worked pretty fine but I’d like to know why you think it’s redundant :slight_smile:

playerNumber[l].ToString()

Appels, you just made me realize how dumb I’ve been for a couple of days trying to figure this simple thing out, my array playerNumber isn’t just an array right, it’s holding not values but classes, so obviously it can’t print out the whole class onto the GUI, hence I have to do playerNumber[l].playerName or such to print something out which I completely forgot! But thank you so much for the help Appels everyone else :slight_smile:

Cheers!

Awesomeness

numPlayers was redundant since it was intialized to 0 and so was i. Then each loop you’d increment numPlayers as well as i… making i and numPlayers equal to each other, which makes numPlayers redundant since you could have just used i. At least from what I recall of the code that’s what it was.

I guess I should of also been more specific when I stated “playerNumber is an array of PlayerPositionData type. Is GUI.Label smart enough to know what to print out there?” And gave you more to go with like does GUI.Label() have an overload to print out your custom class? Since that I beleive was what that error was complaining about.

static function Label (position : Rect, text : String) : void 
static function Label (position : Rect, image : Texture) : void 
static function Label (position : Rect, content : GUIContent) : void 
static function Label (position : Rect, text : String, style : GUIStyle) : void 
static function Label (position : Rect, image : Texture, style : GUIStyle) : void 
static function Label (position : Rect, content : GUIContent, style : GUIStyle) : void

PlayerPositionData couldn’t be casted to any of the above functions, and the following didn’t exist so it threw an error complaining that the function could not be found.

static function Label (position : Rect, data : PlayerPositionData) : void

Lol Aoon, you’re right again, my bad, I didn’t think of that, thanks for pointing that out about numPlayers :slight_smile:

I got the GUI everything else to work perfect now, thanks a lot again everyone!

In Relation to this, I have found out, that in some cases Unity parses function calls with incorrect parameters and when executed, it gives the error of the function not existing rather than incorrect parameters.
This seems to related to .NET but I’m not sure.

Hopefully this will get patched, as it can cause quite some problems XD