You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Matt Ellis edited this page Mar 26, 2018
·
3 revisions
If the new keyword is used to create a MonoBehaviour, the call will fail at run time. This is because a MonoBehaviour is a component, and needs to be attached to a GameObject. Without being attached, the special methods such as Start and Update, etc. won't get called.
This inspection will highlight any attempts to new a MonoBehaviour derived class, and provides an Alt+Enter quick fix to rewrite the new as a call to GameObject.AddComponent<T>(), allowing you to choose which GameObject to add the new component to.
This inspection corresponds to the Unity runtime error "You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed".