I’ve got a ScriptableObject called UnlockSettings that I want to use as a Singleton. The code is like this:
using UnityEngine;
using System.Linq;
public class UnlockSettings : ScriptableObject
{
private static UnlockSettings _instance;
public static UnlockSettings Instance
{
get
{
if (!_instance)
{
_instance = Resources.FindObjectsOfTypeAll<UnlockSettings>().FirstOrDefault();
}
return _instance;
}
}
}
I’ve ensure there is 1 instance of UnlockSettings asset in my Project window, in the root of /Assets. A strange thing happens where Resources.FindObjectsOfTypeAll will null.
What seems to fix it temporarily is if I actually Click on the UnlockSettings asset file (which brings it up on the Inspector) and hit Play again, then it works, until eventually it doesn’t again.
What’s going on here?