Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRanvir Sahota
9,844 PointsWhy use a prefab when the object is only used once?
A prefab is used for when duplicates of the object will be made. But some prefabs will not have duplicates so why make them into prefabs? Examples: bird, player, and Environment are all used once but yet they are all prefabs.
1 Answer
Jennifer Gerbl
8,772 PointsFor teaching purposes, it is kept easy but I would still say that saving these objects in prefabs is a good practice to do. For example, if you want to load a new scene with a new level into your game you can easily reuse your player or enemy prefab. Additionally, you keep your game scalable. You could easily add a second enemy to change the difficulty level of the game for example. And you can instantiate prefabs at runtime very easily. You could spawn the enemy bird some seconds later while the frog is already collecting flies.
And another advantage is that the prefab doesnβt change if you misclick. While changing some things in your scene you could easily end up changing your frog without noticing it. Afterwards you would have to search for the mistake. If you have a prefab you could just delete the prefab from your scene and add it again.
Daniel Diemer
1,937 PointsDaniel Diemer
1,937 PointsI could be wrong as I don't understand everything yet, but I think they did it that way so beginners could drag and drop into the scene without having to setup the lighting or all the other parts of the prefab that they had not talked about yet.
If you were making the game yourself, I'm not sure that you would make all of those into a prefab. Maybe it is good practice so you can easily re-use them later in another game or additionally in this game if you change your scope of the game.