GUI.Button and UnityEngine.UI.Button class conflict

Hello, i was trying to access the Button component from a script but i fould i wasnt able to as the Type Button was already in use from the GUI.Button class.
I was able to access the correct one by using UnityEngine.UI.Button as the type, im not sure if this is viable for future use or it is even easy to rename the class.
For example i had to use UnityEngine.UI.Button button = StartButton.GetComponent<UnityEngine.UI.Button>();

I hope this can be resolved!

There’s nothing to resolve. This is how the language works. How else would you expect it to figure out which one you want? Telepathy? This is why there are separate namespaces: So we don’t have to have silly convoluted names for everything just in case of a conflict, but can just call a button a button.

Either use the fully-qualified name (UnityEngine.UI.Button) or extend the button script (public class SillyButtonName : UnityEngine.UI.Button).

Or use a type alias: (using SillyButtonName = UnityEngine.UI.Button), but you have to do that in every file that uses it.

Wait, I’m confused. How would the compiler get GUI.Button confused with UnityEditor.UI.Button? One’s a static function and one’s a class; it’s not possible to confuse them, because GUI.Button is always going to be called as GUI.Button.

You can avoid the verbosity of UnityEngine.UI.Button with “using UnityEngine.UI;” at the top of your script file, if that’s what your issue is.

(Sidenote: This is a mistake that Unity learned from. In 2.0, it introduced the GUI class, and caused many issues for people who had created their own classes called “GUI” during 1.x. Most of the new classes introduced since then have been put into namespaces to prevent such conflicts.)