Skip to main content

Quick Start

This guide shows the quickest way to get a loot table working. The assets from the completed guide can be found in the example map's LV_QuickStart level.

Create a Struct

This structure will hold the data we will reference with the loot table.

  1. Navigate to your desired folder in the content browser.
  2. Right click, and under the Blueprints category, select Structure.
  3. Name the structure STR_Fruits and open it.
  4. Add a variable, then change its type to Text and its name to DisplayName.
note

To keep things simple, we'll just include a DisplayName variable with type Text. In your structures, you may add any data you wish.

Create a Data Table

Now that we have the struct defining our data, we can create a Data Table which holds the data we will reference.

  1. Right click in the content browser and under the 'Miscellaneous' category, select 'Data Table'.
  2. A configuration dialog will open. Select 'STR_Fruits' as the row structure of the Data Table.
  3. Name the data table 'DT_Fruits' and open it.
  4. Perform this three times, for row names 'Apple', 'Banana', and 'Orange':
    1. Click 'Add' to add a new row to the table.
    2. Rename the row according to the name above.
    3. Change the DisplayName variable according to the name above.
  5. After finishing, your data table should appear like this:

Create a Loot Table Template

  1. Navigate to your desired folder in the content browser.
  2. Right click, and under 'Miscellaneous' category, select 'Loot Table Template'.
  3. A configuration dialog will open:

The Source Row Struct is the row struct used by all referenced data tables and loot tables.

  1. Select STR_Fruits as the Source Row Struct.
  2. Leave Distribution Type as STUnlimited Dist.

The Distribution Type affects how random items are generated by the loot table. See Discrete Distributions for more info.

  1. Click confirm. A new Loot Table Template asset will be created in the current folder.
  2. Name the asset 'LT_Fruits'.
  3. Double-click the asset to open up the Asset Editor:

The Loot Table Template Asset Editor is used to define loot table 'templates' which can be instantiated into Loot Tables at runtime. Think of Templates as defining what a Loot Table will contain, and Loot Tables as the actual object which is sampled from. Templates may only be created and edited within the editor, while Loot Tables may be created and edited at runtime.

  1. Perform this three times, once for each of 'Apple', 'Banana', and 'Orange':
    1. Click the Add button to create a new row in the Authoring tab. Select the newly created row.
    2. In the Row Editor tab:
      1. Change 'Row Name' to the name listed above.
      2. Change 'Ref Table' to 'DT_Fruits'.
      3. Change 'Ref Row Name' to the name listed above.
      4. Change 'Weight' to 100.
  2. After finishing, your asset should look like this:

Because Auto-Compile is on by default, your build tab should show the compiled loot table template:

Instantiate the Loot Table

Now we will create the Loot Table at runtime from our compiled Loot Table Template. For this tutorial, we will spawn the Loot Table in an actor blueprint, but you may instantiate the loot table in any runtime class.

  1. Create a new actor blueprint.
  2. Add new variables:
    1. Add a new variable named Random Stream and set its type to Random Stream.
    2. Add a new variable named Template and set its type to ST Loot Table Template. Change its default to our template LT_Fruits.
    3. Add a new variable named Loot Table and set its type to ST Loot Table.

  1. Add functions starting from the Begin Play event and connect their execution pins:

The random stream is used for random number generation. The seed determines what loot will be generated; The same seed always yields the same loot. Here we will initialize the stream with a random seed.

tip

The Outer for the Loot Table should usually be the object which stores your loot tables. It's recommended to have it be an authoritative, non-replicated object. We use the actor blueprint in this tutorial to keep things simple.

Sample from the Loot Table

Finally, we can sample from the loot table to get our random fruit(s).

  1. Add the Bulk Sample (Ordered) function from the loot table:

The Sample Count parameter is the number of times to sample from the loot table. Each 'Sample' yields one row.

The Bulk Sample (Ordered) function is one of three sampling functions you may use. This function returns multiple samples as an array sequence of Data Table Row Handles.

For simplicity, we will use UE5's debug print function to show what we sample.

  1. Add the following functions after the Bulk Sample (Ordered) function:

This will print out each row we sample in the order that they're sampled.

Result

  1. Open up a level and add our BP_QuickStart actor into the level.
  2. Press Play In Editor.
  3. You should see debug messages similar to these:

The messages you see will be random between Apple, Banana, and Orange with 33% probability for each one.

This concludes the quick start guide. For more in-depth use cases, see other guides.