Legacy Documentation: Version 5.2
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorUtility.CreateGameObjectWithHideFlags

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public static function CreateGameObjectWithHideFlags(name: string, flags: HideFlags, params components: Type[]): GameObject;
public static GameObject CreateGameObjectWithHideFlags(string name, HideFlags flags, params Type[] components);

Parameters

Description

Creates a game object with HideFlags and specified components.

This is very similar to creating a GameObject the usual way, except it sets the specified HideFlags immediately.

Editor Window that shows how does the example looks.

	// Simple script that lets you manage the flags of an instanceID from a
	// GameObject or lets you create a new empty GameObject with custom flags set

class GameObjectFlags extends EditorWindow {

var objName : String = "GameObject"; var instanceID : int = 0; var create : boolean = true; var go : GameObject = null;

var hideHierarchy : boolean = false;

@MenuItem("Examples/GameObject flags") static function Init() { var window = GetWindow(GameObjectFlags); window.Show(); }

function OnGUI() { create = EditorGUILayout.Toggle("Create a GO:", create); GUI.enabled = create; objName = EditorGUILayout.TextField("GameObject Name:", objName); if(GUILayout.Button("Create")) { var created = EditorUtility.CreateGameObjectWithHideFlags( objName, hideHierarchy ? HideFlags.HideInHierarchy : 0); Debug.Log("Created GameObject ID: " + created.GetInstanceID()); } GUI.enabled = !create; EditorGUILayout.BeginHorizontal(); instanceID = EditorGUILayout.IntField("Instance ID:", instanceID); if(GUILayout.Button("Search & Update flags")) { go = null; go = EditorUtility.InstanceIDToObject(instanceID); if(go) go.hideFlags = hideHierarchy ? HideFlags.HideInHierarchy : 0; } EditorGUILayout.EndHorizontal();

if(!go) EditorGUILayout.LabelField("Object: ","No object was found"); else EditorGUILayout.LabelField("Object: ", go.name);

GUI.enabled = true; hideHierarchy = EditorGUILayout.Toggle("HideInHierarchy", hideHierarchy);

} }