JetBrains / resharper-unity

Unity support for both ReSharper and Rider
Apache License 2.0
1.21k stars 134 forks source link

Add inspection for script with name of built in component, e.g. "Grid" #597

Open citizenmatt opened 6 years ago

citizenmatt commented 6 years ago

If a script has the same name as a built in component, the following warning is displayed in the Unity console:

Script 'Grid' has the same name as built-in Unity component. AddComponent and GetComponent will not work with this script.

Presumably, this means GameObject.AddComponent(string) and GameObject.GetComponent(string), both of which are marked as obsolete, and should be replaced with typesafe versions, using typeof or type parameters.

However, the warning remains. Add an inspection to mimic this warning inside the code editor.

Also, add a code inspection wiki entry to provide more details. Will probably need more information on the list of known components and why it doesn't work with AddComponent/GetComponent.

citizenmatt commented 5 years ago

See also #597

joselluis7 commented 5 years ago

It is because you are using for the script's name a name that unity uses for one of their internal component or Object. Eg: "Camera" you cannot have other thing with this name