Skip to content

ScriptableObjects must be instantiated with ScriptableObject.CreateInstance instead of new

Matt Ellis edited this page Feb 19, 2019 · 2 revisions

If the new keyword is used to create a ScriptableObject, the call will fail at run time. This is because a ScriptableObject needs to be created by the Unity engine so that Unity can call the special methods Start, Update, etc.

This inspection will highlight any attempts to new a ScriptableObject derived class, and provides an Alt+Enter quick fix to rewrite the new as a call to ScriptableObject.CreateInstance<T>().

This inspection corresponds to the Unity runtime warning:

ClassName must be instantiated using the ScriptableObject.CreateInstance method instead of new ClassName

Clone this wiki locally