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.

Question GameObject should NOT exist in the scene YET

Discussion in 'Scripting' started by ateryubone, Nov 28, 2022.

  1. ateryubone

    ateryubone

    Joined:
    Nov 28, 2022
    Posts:
    15
    I have a GameObject that is cloned when I press a button. But I don't want the original object to exist, because I just want to spawn copies of the object when I press the button, but I don't want any copies of the object to exist until the button is pressed.

    How do I do this?
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    3,369
    Make the game object a prefab. Reference prefab in script. Instantiate() prefab. Profit.
     
    Bunny83 likes this.
  3. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,161
    Agree with spiney199, but you can also clone copies of objects which are inactive. They're in the scene but the player can't see it. This is handy if you need to clone things that are constructed or heavily modified at runtime.
     
    Bunny83 and spiney199 like this.