Skip to content

Instantly share code, notes, and snippets.

@jackyyang09
Last active March 3, 2020 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackyyang09/f6cf3acb5c1aae99b24cb88a37fe17e7 to your computer and use it in GitHub Desktop.
Save jackyyang09/f6cf3acb5c1aae99b24cb88a37fe17e7 to your computer and use it in GitHub Desktop.
A somewhat extended version of a gist uploaded by user gekidoslair that adds two new lines of code. New code selects the new object created and adds the creation of the object to the undo stack
using UnityEditor;
using UnityEngine;
namespace MWU.Shared.Utilities
{
/// <summary>
/// Adds 'Create Empty at Root' shortcut for the GameObject / right-click context menu to create an empty gameobject at 0,0,0
/// Original can be found here: https://gist.github.com/gekidoslair/359535dd108ce3dfac6b564ad37e42fe
/// </summary>
public class CreateEmptyAtRoot : MonoBehaviour
{
[MenuItem("GameObject/Create Empty at Root", false, 0)]
public static void Create()
{
var go = new GameObject();
go.name = "GameObject";
go.transform.position = Vector3.zero;
go.transform.rotation = Quaternion.identity;
Undo.RegisterCreatedObjectUndo(go, "Added new gameobject at root");
Selection.activeTransform = go.transform;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment