Parameter | Description |
---|---|
className | The type of the ScriptableObject to create, as the name of the type. |
type | The type of the ScriptableObject to create, as a System.Type instance. |
ScriptableObject The created ScriptableObject.
Creates an instance of a scriptable object.
To easily create a ScriptableObject instance that is bound to a .asset file via the Editor user interface, consider using CreateAssetMenuAttribute.
using UnityEngine;
public class MyData : ScriptableObject { public int value; }
public class CreateInstance : MonoBehaviour { void Start() { ScriptableObject nonGenericInstance = ScriptableObject.CreateInstance(typeof(MyData)); ((MyData)nonGenericInstance).value = 20; Debug.Log("Non-generic instance value: " + ((MyData)nonGenericInstance).value); } }
T The created ScriptableObject.
Creates an instance of a scriptable object.
To easily create a ScriptableObject instance that is bound to a .asset file via the Editor user interface, consider using CreateAssetMenuAttribute.
using UnityEngine;
public class MyData : ScriptableObject { public int value; }
public class CreateInstanceGeneric : MonoBehaviour { void Start() { MyData genericInstance = ScriptableObject.CreateInstance<MyData>(); genericInstance.value = 10; Debug.Log("Generic instance value: " + genericInstance.value); } }