Get the latest Education e-news
 
  • Orchestrating Gameworlds: A Prefab Primer

    [07.10.18]
    - Nathan Cheever
  • 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. It's a concept I've made sure to use across past projects like Six Days in Fallujah, Prey 2, and Mafia 3.

    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

    1. Repeat occurrences only have to be created once. When the original prefab is modified, all instances are updated.
    2. 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.

Comments

comments powered by Disqus