Spawning Objects
Last updated
Was this helpful?
Last updated
Was this helpful?
There are 5 different ways (currently) to use the Instantiate() function to create or "spawn" pre-made objects.
The most basic use of it is as follows:
Define the gameObject within the script within the class, but before the Start() function:
In this example, the object is named "thing".
Then, in your script where you want to create or "spawn" the object add this:
Spawned objects with the simplest version of Instantiate() will spawn with the transform, components, and settings as the original object.
You can put this into a variable:
This is helpful when you want to create several in a loop, changing copies individually.
Many game artists use the Instantiate() function with so they don't need to spawn each part individually.
Example of copies of a game object called "thing" spawning each time the player hits the letter S:
In your Hierarchy window, the spawned copies will appear as clones:
Other forms of the Instantiate() function make it easy to control the position and rotation as well as determining the spawned objects' parent object.
REMEMBER: Add the script to a game object in the scene. It will not work if it does not exist in the game.
Check out the and the different ways to use it.