CreateInstance
Creates a new instance of a serialized object of type T.
Read time 1 minuteLast updated 3 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
CreateInstance<T>()
Creates a new instance of a serialized object of type T.
public static T CreateInstance<T>() where T : Object
Returns
Type | Description |
|---|---|
| T | The new object, as type |
Remarks
Use this method to create any type of serialized object in the Unity Editor. The new instance uses default values. This generic overload returns the object as type , so you don't need to cast it.
TCreateInstance(Type)
Creates a new instance of a serialized object of the specified type.
public static Object CreateInstance(Type type)
Parameters
The type of object to create.
Returns
Type | Description |
|---|---|
| Object | The new object. |
Remarks
Use this method to create any type of serialized object in the Unity Editor. The new instance uses default values.
Examples
using UnityEngine;using UnityEditor;public class CreateInstanceExample{ [MenuItem("ObjectFactoryExample/Create Material Asset")] public void CreateMaterialEditor() { Material material = ObjectFactory.CreateInstance<Material>(); material.shader = Shader.Find("Transparent/Diffuse"); AssetDatabase.CreateAsset(material, "Assets/newMaterial.mat"); }}