The analyzer has detected an improper creation of the 'MonoBehaviour' or 'ScriptableObject' class instance using the 'new' operator. Objects created in this way are not linked to the engine, so Unity-specific methods such as 'Update', 'Awake', 'OnEnable', and others are not called.
Take a look at an example below:
class ExampleSO: ScriptableObject
....
class ExampleComponent: MonoBehaviour
....
void Awake
{
var scriptableObject = new ExampleSO();
var component = new ExampleComponent();
}
To avoid potential issues, use one of the following methods instead of the 'new' operator to create instances of the classes:
Here is the fixed code:
class ExampleSO: ScriptableObject
....
class ExampleComponent: MonoBehaviour
....
void Awake
{
var scriptableObject = ScriptableObject.CreateInstance<ExampleSO>();
var component = this.gameObject.AddComponent<ExampleComponent>();
}
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders:
Take
a chance!