Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

How to avoid error message when using DestroyImmediate in Editor

$
0
0
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?

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>