Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


CreateGameObject

Creates a new GameObject.
Read time 1 minuteLast updated 12 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule

CreateGameObject(Scene, HideFlags, string, Type[])

Creates a new GameObject.
public static GameObject CreateGameObject(Scene scene, HideFlags hideFlags, string name, params Type[] types)

Parameters

scene

Scene where the GameObject should be created.

hideFlags

HideFlags to assign to the GameObject.

name

Name of the GameObject.

types

The optional types to add to the GameObject when created.

Returns

Type

Description

GameObjectReturns the GameObject that was created.

Examples

using UnityEngine;using UnityEditor;public class CreateComponentExample{ [MenuItem("ObjectFactoryExample/Create Camera GameObject")] public void CreateCameraEditor() { Selection.activeGameObject = ObjectFactory.CreateGameObject("Camera", typeof(Camera)); }}

CreateGameObject(string, Type[])

Creates a new GameObject.
public static GameObject CreateGameObject(string name, params Type[] types)

Parameters

name

Name of the GameObject.

types

The optional types to add to the GameObject when created.

Returns

Type

Description

GameObjectReturns the GameObject that was created.

Examples

using UnityEngine;using UnityEditor;public class CreateComponentExample{ [MenuItem("ObjectFactoryExample/Create Camera GameObject")] public void CreateCameraEditor() { Selection.activeGameObject = ObjectFactory.CreateGameObject("Camera", typeof(Camera)); }}