# Game Object Create Menu

## What for?

In **Assets\\\_Main\Scripts\Editor\\** you can find <mark style="color:red;">**CustomGameObjectCreateMenu.cs**</mark> that is used to fill GameObject create menu that looks like this:

<figure><img src="https://1613353771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fygjewtla1W7kzTTIpGWq%2Fuploads%2FSK53nqUpqNg7Uwvgg9L4%2Fimage.png?alt=media&#x26;token=d9585e05-667d-4433-942a-414ed234eb89" alt=""><figcaption><p>Game Object create menu (right mouse click on scene Hierarchy)</p></figcaption></figure>

Vibro Button above is created by ***template*** and other objects should too.\
You can find ***templates*** here: **Assets\\\_Main\Prefabs\Common\GameObjectTemplates**.

{% hint style="warning" %}
You shouldn't rename basic template prefabs in **Assets\\\_Main\Prefabs\Common\GameObjectTemplates**.\
\
\&#xNAN;*<mark style="color:green;">**But you can modify**</mark>* **content** of each template, so next time if you will create object from game object menu -> it will be created with changes you made in template prefab.
{% endhint %}

## How to add new create menu items?

1\) Add prefab in **Assets\\\_Main\Prefabs\Common\GameObjectTemplates** that you want to create from GameObject menu. You should make unique name, because <mark style="color:red;">**CustomGameObjectCreateMenu.cs**</mark> finds templates by names or by class. Name should be "*name*Template";

2\) Add label "GameObjectTemplate" to your prefab in right down corner of editor:

<figure><img src="https://1613353771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fygjewtla1W7kzTTIpGWq%2Fuploads%2FJKXVRoV4SXmLPYWTiuka%2Fimage.png?alt=media&#x26;token=e5d576a3-5249-4c2f-b758-b51140733d00" alt=""><figcaption><p>Adding GameObjectTemplate label to your GameObject prefab</p></figcaption></figure>

3\) Open <mark style="color:red;">**CustomGameObjectCreateMenu.cs**</mark> and add method that will fill up GameObject create menu with new item.\
for example here is Vibro Button add method:

{% code lineNumbers="true" fullWidth="false" %}

```csharp
[MenuItem("GameObject/UI/Vibro Button")]
public static void VibroButtonCreate() {
    var btn = CreateGameObject("btnVibroTemplate", "btnVibro");
    CreateCanvasIfNoYet(btn);
}
```

{% endcode %}

* in 1 line \[MenuItem()] defines location of create button in GameObject menu and <mark style="color:red;">**you must start it with**</mark> <mark style="color:blue;">**"GameObject/"**</mark>;
* in 3 line ***CreateGameObject*** method takes "btnVibroTemplate" as template prefab name and "btnVibro" as output gameObject name;
* in 4 line creates canvas if there is no yet (specific case for UI elements)

Like this you can speed up creating objects by templates in the future.
