• UE4: Repeating Terrain – using blueprints and randomisation

    When creating levels for games, you will often want to place sequences of terrain features which repeat, for example: stairs, fences, and other repetitive details.

    When making stairs, you could model an entire staircase in your 3D-modelling package specifically for the area at hand, but that requires you (or your artists) to make a lot of customised, single-use meshes.

    Alternatively, you could model individual steps (or a mesh with a small number of steps) and repeat those until your staircase is the right height.  Constantly using the same model will most likely make the repetitive use of the same texture extremely obvious and jarring.

    This article proposes a solution to this problem: to create a number of unique meshes which are all variations on the same section of the repeating terrain, and to then use a blueprint to automatically select and place the individual meshes to build up the desired length of terrain.

    For example, to model a dozen variations of a single step, and then have a blueprint which randomly (or sequentially) picks one of those variations and places it appropriately until it has built the entire staircase.

    This allows the level designer to quickly and easily create repetitive terrain features, each with a unique look, and without requiring custom assets to be made for each individual use case.

    Four sets of stairs generated from four step models using the system described in this tutorial.

    The following short tutorial will explain how to set up a configurable version of this system using Blueprints.

     

    BaseRepeatingTerrain

    Adding new components to a blueprint is not something that can be done from a global macro, so you will need a base blueprint to hold the common functions used by the system.

    BaseRepeatingTerrain

    The blueprint will need two functions: one for creating the next mesh in the sequence, and another for creating an entire sequence of meshes.
    It will also need an Integer variable named SequenceNumber, which will be used to keep track of the current position in a sequence when creating the meshes in linear (rather than random) order.

     

    The first function, CreateNextMeshComponent, creates a new static mesh component, and then sets it to use one of the models provided to it in the array.  It branches out to two different ways to pick the model – one picks a random entry from the list, the other picks the next one in sequence.

     

    The second function, CreateMeshSequence, creates the entire sequence of meshes at the desired offsets.  It consists of a loop which repeatedly runs the earlier function the desired number of times, each with a different set of coordinates based on the function’s parameters.

     

     

    GenericRepeatingTerrain

    The two functions described above are enough to use the system fairly easily, by creating a child blueprint of this one and calling the functions with the appropriate inputs.

    However, that’s still a fair bit of work for each use case; instead, we will create a generic child blueprint with parameters for each of the settings, allowing it to be simply dropped into a level and configured in the properties panel.  Each of the properties is used in the construction script, where it is wired directly into a call to the Create Mesh Sequence function.

     

    Alternatively, you could combine the properties, construction script, and helper functions in a single blueprint class, but splitting them in two allows for other child blueprints to follow the same mould.

    Another very powerful use for this system – though one which is not directly covered in this tutorial – would be to use the system to randomly generate segments along a spline.  In that case, the base function would need to be changed slightly to allow allow the creation of Spine Mesh components instead of Static Mesh ones.

    [2018] That thought would later inspire me to create the far more powerful NV Spline Tools – a system for setting up a modular sequence of meshes to follow the path of a spline.

     

    The meshes

    The creation of the actual meshes to use for this system is beyond the scope of this tutorial, but in brief each segment is expected to be roughly the same size and to snap properly into the place with the next segment at the offset configured in the blueprint’s properties.

    Download

    You can download a zip file containing importable versions of the two Blueprint classes described in the tutorial, below:


     Leave a reply

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    fifty nine + = sixty five