Hi,
I don’t understand when and why should I use prefabs instead of game objects ?
I understand what is a prefab, but couldn’t figure out the when and why it’s practical to use them.
Thanks in advance.
Hi,
I don’t understand when and why should I use prefabs instead of game objects ?
I understand what is a prefab, but couldn’t figure out the when and why it’s practical to use them.
Thanks in advance.
Hey there Zoltar.
What exactly do you mean when you say Prefabs instead of GameObjects? Prefabs are usually made up of a hierarchy of Gameobjects, so I think there might be some confusion there. Prefabs are extremely useful in that they allow you to assign scripts/materials/other variables to a GameObject or hierarchy of GameObjects and keep them saved that way to be loaded at a later time. This makes it MUCH easier to bring things into your game environment by letting you do all the work once, save it to a prefab, and then just call that prefab whenever you like instead of having to reconstruct all the values again.
Here’s an example:
Say you create a character in your game. That character likely needs some kind of script that holds the information (stats/inventory/spells) of that character. That character also needs a collision box, and probably a Navigation Agent (if it’s an NPC). All of these things have values that need to be set, like Maximum Health, and Spell Points. Once you finish setting these things, you can drag it into your prefabs folder and call on it whenever you like.
Prefab just means “Pre-Fabricated”, or “Already assigned what it needs.” They can be instantiated from scripts or dragged into the scene from the editor and can be used to create anything from weapons to characters.
Hope that helps some :).
Well in many ways actually, but i mostly use them to instantiate (clone) a object for say: build a terraing or some structure made of little boxes (box prefab), shoot a ball (you instantiate it and add force or speed), create a rain of things… and a lot more