Prefabs are not a new topic to game developers. These will be referenced in future articles of mine, so here's an overview to a concept for mastering massive content.
Introduction
If you’ve ever had to deal with tons of objects across multiple scenes, you’ll inevitably wish you could group similar or exact copies together for quicker management. If you’ve added a desk lamp to 30 different office rooms in 15 different scenes, wouldn't it be nice to turn up the that light's intensity once instead of 450 times?
That’s the power of prefabs.
So, what exactly is a prefab? It's a collection of game objects used in multiple places across the game.
A Prefab should be a Scene. The only thing that should make a prefab different than a scene (a level, map, environment, etc.) is it exists inside a scene. A large city scene can have several small prefab neighborhoods and those in turn can have repeatable prefab houses inside of each.
Some game engines develop prefabs as a unique feature, separate from a scene's format. By developing a prefab as an extension of a classic scene means they inherit all features and power scene editing has!
Any feature that exists for a scene should exist for a prefab:
A collection of models (a bench, a bus stop sign, a garbage can).
A building with AI navigation and interaction nodes.
An enemy with a unique change (BadGuy_Type_4 with dual pistols).
A complex script sequence (depending on project's script file handling).
A skybox with all associated FX and animation.
A Security Door (a door model & logic, security palm switch & logic, emergency lighting & logic, surrounded by cover nodes & path volumes).
Advantages
Repeat occurrences only have to be created once. When the original prefab is modified, all instances are updated.
Multiple people can work on the same scene by partitioning the scene into prefabs. Each user works on their individual prefab, testing their work in the master scene.
Game Usage
Prefabs should be created in the editor as a new scene or from a selection within an existing scene. The most common type is a Static Prefab. They can be saved to the game library for reuse later. When the game is built and run, all static prefabs are ungrouped (sometimes called exploded). All parts should have their name prefixed to the prefab's unique name for reference. All game logic now points to unique items maintaining unique scripting.
In the editor they can also be exploded into an existing scene to creating unique, free roaming objects, no longer connected to its source.
Aside from static prefabs, Dynamic Prefabs are another option. These are used to stream in content. If done right, prefabs can be the primary means all content is contained and streamed into the game.
With procedural systems like Houdini, you could even extend prefabs into becoming Smart Prefabs. These feature a set of rules to decide what, where, and when to place a variety objects at different times. This article is only about the core prefab concept though.
The Concept
Every scene can be made with a number of prefabs. Take a look at the following diagram as an example:
Now let's see how prefabs let several people work on the scene:
The Art Team works on the Ground Terrain A location:
Artist 1 models Building D with indoor lighting to be used in 2 locations.
Artist 2 models Building C to be used in 4 locations.
Artist 3 models Building B to be used in 3 locations.
Artist 4 models Building A with indoor lighting to be used in 4 locations.
Artist 5 is lighting the whole scene. Some lighting features on-off logic with Gameplay.
The Audio department is working on ambient Sound for the scene, mixed with Gameplay.
The Design Team is providing gameplay to the Ground Terrain B location:
Designer 3 is creating a generic prefab for assigning AI and stats for a Train Event.
Designer 2 is creating City Tower logic to be used in 4 separate places in Ground B.
And lastly, Designer 1 is providing gameplay for the overall scene in the Master Scene.
When any person is finished, they check their prefab into Source Control to share with the rest o