Code inspection: Cannot resolve component or scriptable object
Several Unity methods accept string literal arguments that represent the name of a type to be added, retrieved, or created. For example, GameObject.AddComponent("TypeName"), GameObject.GetComponent("TypeName"), or ScriptableObject.CreateInstance("TypeName").
This inspection flags cases where the provided string literal cannot be resolved to any known Unity Component, MonoBehaviour, or ScriptableObject type in your project or referenced Unity libraries.
The inspection also ensures that the resolved type is valid for the specific operation. For instance, when using AddComponent("TypeName"), the type must not only exist but also inherit from MonoBehaviour.
public class MyScript : MonoBehaviour {
void Start() {
// "UnknownType" does not exist
gameObject.AddComponent("UnknownType");
}
}
public class MyScript : MonoBehaviour {
void Start() {
// Use an existing and valid type name
gameObject.AddComponent("MyOtherMonoBehaviour");
}
}
26 March 2026