Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Hotkey for Pasting Prefabs?

Discussion in 'Prefabs' started by Koaske, Jun 20, 2021.

  1. Koaske

    Koaske

    Joined:
    Mar 30, 2015
    Posts:
    22
    Is there a hot key or a command that I can use to paste a lot of copies of a given prefab on the scene?

    I know I can use CTRL+D to duplicate the prefab, but doing so seems a bit tedious.

    Preferably, I'd also want to space the prefabs out at even intervals, e.g. at x= 1, 2, 3,..

    I'm aware that I can change the grid and snap settings to help with these, but is there some other/quicker way?
     
  2. kamicazer7

    kamicazer7

    Joined:
    Oct 27, 2012
    Posts:
    7
    Not as far as I now, but making an editor code to do that is quite easy:


    [MenuItem("Helper/Copy 50 times")]
    public static void CopyManyTimes()
    {
    GameObject go = Selection.activeGameObject;
    if (go == null)
    return;

    float relativeToX = 1f;
    Vector3 newPos = go.transform.position;
    for (int i = 0; i < 50; i++)
    {
    GameObject newInstance = GameObject.Instantiate(go, go.transform.parent);
    newPos.x += relativeToX;
    newInstance.transform.position = newPos;
    }
    }
     
    Last edited: Jun 21, 2021
    Koaske likes this.