- Home /
How to avoid error message when using DestroyImmediate in Editor
I have created a Singleton pattern for ScriptableObjects. Whenever I have a scriptableObject that I only want 1 instance of I let it inherit from my SingletonSO class. See here:
public class SingletonSO : ScriptableObject
{
private void Awake()
{
string myTypeString = "t:" + this.GetType().ToString();
string[] guids = UnityEditor.AssetDatabase.FindAssets(myTypeString);
if (guids.Length > 0)
{
DestroyImmediate(this);
}
}
}
However I receive an error message when the DestroyImmediate method occurs:
NullReferenceException: Object reference not set to an instance of an object UnityEditor.ProjectWindowUtil.CreateAsset (UnityEngine.Object asset, System.String pathName) (at :0)
Is there any way to tell the UnityEditor.ProjectWindowUtil that I have destroyed the object and it should not process it anymore?
Your answer
Follow this Question
Related Questions
Display Custom Inspectors for each class in a List<> 1 Answer
Unity 2017.2.0p3 Editor Animation InvalidCastException Error !! 0 Answers
How do I fix error code cs1056: Unexpected Character 1 Answer
Unity Custom Inspector - Resources.LoadAll() returns 0 element. 1 Answer
How to set Inspector veiw for Hierarchy view vs Project view. 0 Answers