Skip to content

Instantly share code, notes, and snippets.

@Oxeren
Oxeren / MySingletonSO.cs
Last active February 15, 2024 04:57
Auto singleton Unity ScriptableObject. Derive your class from this class (and use your class as the generic type), create an instance in the Resources folder (name of the instance must be the same as the name of your class). Then you will be able to access the singleton via static Instance property without having to add boilerplate code.
// Example Scriptable Object. Instance must be placed in Resources folder and have the same name as the class, type of generic parameter must be your class.
using UnityEngine;
[CreateAssetMenu(fileName = "MySingletonSO")]
public class MySingletonSO : SingletonScriptableObject<MySingletonSO>
{
// Here goes your data. This class can be called by the static Instance property, which will automatically locate the instance in the Resources folder.
}