CreateGameObject
Creates a new GameObject with the specified name and components, in a specific scene and with hide flags.
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
CreateGameObject(Scene, HideFlags, string, Type[])
Creates a new GameObject with the specified name and components, in a specific scene and with hide flags.
public static GameObject CreateGameObject(Scene scene, HideFlags hideFlags, string name, params Type[] types)
Parameters
Returns
Type | Description |
|---|---|
| GameObject | The GameObject that the method created. |
Remarks
The method throws an exception if isn't valid.
sceneCreateGameObject(string, Type[])
Creates a new GameObject with the specified name and components.
public static GameObject CreateGameObject(string name, params Type[] types)
Parameters
Returns
Type | Description |
|---|---|
| GameObject | The GameObject that the method created. |
Remarks
The method adds the components while the GameObject is inactive, then activates it and gives it the default parent for new objects. To create the GameObject in a specific scene, use the overload that takes a Scene.
Examples
using UnityEngine;using UnityEditor;public class CreateComponentExample{ [MenuItem("ObjectFactoryExample/Create Camera GameObject")] public void CreateCameraEditor() { Selection.activeGameObject = ObjectFactory.CreateGameObject("Camera", typeof(Camera)); }}