Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Game Development How to Make a Video Game Game Audio Additional Audio Scripting

Ranvir Sahota
Ranvir Sahota
9,844 Points

Why 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.

Daniel Diemer
Daniel Diemer
1,937 Points

I 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.

1 Answer

For 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.