| Parameter | Description |
|---|---|
| type | The type of object to create. |
Object The new object.
Creates a new instance of a serialized object of the specified type.
Use this method to create any type of serialized object in the Unity Editor. The new instance uses default values.
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"); } }
T
The new object, as type T.
Creates a new instance of a serialized object of type T.
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 T, so you don't need to cast it.