- Home /
Spawn: Instantiate GameObject
What is the recommended way to spawn/instantiate a new GameObject from a Prefab? What seems to be working right now is that I keep a public reference to a GameObject so that I can assign the Prefab via the inspector. However seems like it would be a PITA to do if you have different types Prefabs. Is there a better way to do this?
Answer by Casiell · Oct 02, 2018 at 07:40 AM
You could keep your prefabs in Resources folder and load them by name or type. Be very careful with this folder as files in it will be added to build even if you will never use them in your game.
I would go with this solution only if I want to have a semi-dynamic system where I can add a lot of things (like items in RPG) and even then I would probably go for editor script of some sort.
Interesting. The game is a simple space invader shooter were enemies and items are just spawning from the top. With the way I have it, I wonder what the ramifications are if terms of memory but I guess I'm only keeping a reference to the prefabs in the script.