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?
↧