Essential Systems / Singletons
Singletons
Enjoying Essential Systems?Leave a reviewLearn to use the included singletons.
Singleton
A singleton for any
MonoBehaviour. The instance must exist in the scene.
public class Test : Singleton<Test>
{
public void TestMethod()
{
Debug.Log("Test");
}
}
public class AnotherTestClass : MonoBehaviour
{
private void Start()
{
Test.Instance.TestMethod();
}
}
SingleSingleton
Like
Singleton, but the instance persists across scenes viaDontDestroyOnLoad.
public class Test : SingleSingleton<Test>
{
public void TestMethod()
{
Debug.Log("Test");
}
}
public class AnotherTestClass : MonoBehaviour
{
private void Start()
{
Test.Instance.TestMethod();
}
}
SingletonScriptableObject
A singleton for a
ScriptableObject. The asset must be placed in aResourcesfolder.
[CreateAssetMenu(fileName = "Test", menuName = "Essentials/Test")]
public class Test : SingletonScriptableObject<Test>
{
public void TestMethod()
{
Debug.Log("Test");
}
}
public class AnotherTestClass : MonoBehaviour
{
private void Start()
{
Test.Instance.TestMethod();
}
}
Last updated

