Prop Generator

by Mike Wuetherick

Let’s dive into the detail of our procedural system. As I mentioned last time, the procedural nature of the environments for the game can be broken into 3 basic layers

  1. Random Loot
  2. Randomized Prop Placement
  3. Random City layout

This post, I’m going to go over the second point – Randomized Prop placement, as this is the core of the entire system.

What is a Prop?

In the system that I’m designing a ‘Prop’ is a hierarchical set of elements that has 3 key behaviours:

  1. Spawn a set of children
  2. Spawn a Random entry from a list of children
  3. Automatic discovery & configuration at Edit time

Hierarchical Spawning

The first key feature is that Props will spawn a collection of children. For example, a section of a level could be built up from a number of different meshes – floors, walls, ceiling for example.  A Prop is the container that we use to spawn the entire section at once – we want each section to have a floor, walls and ceilings.  The Prop doesn’t know or care about placement of these elements, all it knows is that when we load the level, we spawn the necessary dependencies.

If we think of a typical location, say a building, it might look something like this:

  • Building
    • Floor
      • Hallway
      • Suite
      • Suite
      • Stairs
      • Elevator
      • Front Entrance

Each of these sub-elements (Hallways, Suites, Front Entrance, Elevator) are containers that manage the child objects within.  A multi-level building is simply a different collection of the same elements, minus the Front Entrance:

  • Building
    • First Floor
    • Second Floor
      • Hallway
      • Suite
      • Suite
      • Stairs
      • Elevator

And so on.

The beauty of this hierarchical system is in it’s simplicity – each element only cares about it’s immediate children and nothing else. So the ‘Floor’ element doesn’t know ‘what’ is in the Hallway or Suite ‘Props’, only that it needs to spawn one.

This is where things get interesting – the key to build an entire environment from a collection of props is that they are hierarchical in nature.  Props can spawn props which can spawn props (and so on).  This scales from individual elements all the way up to buildings and city blocks.

Randomized Spawning

The second feature is the ability to spawn a random entry from a list of children. What this means is that a Prop can have a collection of children, but when spawning, will only pick ONE of the list of children, instead of spawning them all like we have described above.  This lets us configure a wide range of potential configurations for our child elements and the Prop will pick one at random during initialization.

For example, to continue our Building example from above, the ‘Suite’ prop might have multiple configurations, like so:

  • Suite
    • 1 bedroom
    • 2 bedroom
    • 3 bedroom

When the Building is initialized, it first spawns the ‘Floor’ Prop and then the ‘Suite’ prop from the list. Instead of the suite spawning all 3 potential layouts, it will randomly pick ONE of them. Some Suite props will be 1 bedroom, some will be 2 bedroom and so on.

This also works in a hierarchical nature, so you can have Random Room Layouts within the Suite – and within a Room have random placement of furniture – a living room Prop might have different furniture, different placement of the furniture, a book case might have random placement of books and so on.

Automatic Discovery & Configuration

This is the most critical piece of the puzzle for me to be able to rapidly set up procedural scenarios – automatic configuration.  As I mentioned before, I’m an extremely lazy designer – and I don’t want to spend a huge amount of time preparing content for use in the game.

With this in mind, the Prop component has the ability to ‘discover’ any child elements in the scene hierarchy and automatically configure itself appropriately.  This makes it very easy to port / migrate an existing Unity scene and turn it into a Procedural scene – we simply add the “Prop’ component to the parent GameObject of a scene element and the Prop will automatically prepare itself.

That’s enough theory for today, next time I’ll jump into a scene and show some examples of how the Prop system is used in practice!

Series Navigation<< New Series – Procedural Cities!Randomizing Props – Procedural Bookshelves! >>

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More