How to replicate Payday's Loot Bag System.

Editor Note: As I was making this post I was fiddling with some nodes here and there and broke some stuff, made some stuff work, and made stuff half work. The struggle of trying to get this to work and understand it is painful, but I’m determined and I hope what I’m sharing is helpful.

To begin with I ended up finding a tutorial on a similar item/object movement mechanic I had been searching for. Here is a link to the video for reference and if anyone else is interested in checking out this gentleman’s other tutorials:
https://www.youtube.com/watch?v=03E8wwD0Iew&t=3624s

Following along with the tutorial, this was my first time working with Data Assets. It seems like a really powerful method of using data but I’m either using it incorrectly or with the mechanics I’m trying to create I’m thinking I should just stick with Structs and Data Tables. I say this because when I try to spawn my item actors within the level and try to have the Parent Actor or Item Spawning Actor set their randomly selected values, the values get selected but only the last selected value gets set as the value for all of the items. Then, when I go and pick up the items, their values either get destroyed with the object that gets destroyed on pick up or the value gets rolled again when I throw the object (it gets respawned in the level) thus setting a new value to all other objects.

After that, when I go to pick up another item it has either that new value, a completely different value, or no value? I say this because once I pick up a second item and throw it my widget that should display a name and value breaks.

Started off by creating the Primary Data Asset for the Items, which has 4 variables:

  • Object Actor which is a class reference of the Actor
  • Object Mesh which is an object reference of the Static Mesh
  • Object Image which is an object reference of the Texture 2D
  • Object Value which is an integer

Next the Item Spawning actor was created, it has two variables:

  • Item Data which is a reference to the Data Asset
  • Value which is an integer (this is where I think I was setting the value of the items)

It also has an Interface for the picking up interaction. (More on that in a bit)

On the Construction Script of the Item Spawning actor, its Static Mesh is used to set up the spawned item’s mesh and enable Simulated Physics pulled from the Item Data variable.


Then the Data Assets were created pulling information from the Primary Data Asset. These were used to create two test items.

With all the above created I was able to set them into the level.

An actor class was created as the parent class to create child actors for the two items which get assigned in the Data Assets as the Object Actor. The Item Base Actor (parent class) uses the Pickup Interface which gathers data from the Primary Data Asset. Inside its construction script the static mesh was used to set the Static Mesh and enable Simulate Physics. It has two variables, 1st for the Primary Data Asset and 2nd for an Integer Value. The actor also has Projectile Movement on it, this gets used once I decide to drop/throw the item I have picked up.


The Pickup Item Interface has two functions:

  • Pickup Object, has an Input that uses an Object Reference of the character being played.
  • Query Asset, has an Output that uses the Primary Data Asset

An Actor Component gets created to manage the inventory of the character, this can be adjusted to have many slots but for my example I am only using 1 slot. The component has 4 variables:

  • Inventory Widget, object reference for the widget that displays the inventory slot.
  • Current Slot Index, integer variable type. (this is used in case there are multiple slots that can be cycled through.)
  • Inventory Slots, an object reference of the Primary Data Asset that gets converted into an Array.
  • Owner REF, object reference of the character being played.

There are 3 functions:

  • Is Slot Free?, verifies whether or not the player has an available inventory slot open to store a picked up object.
  • Query Inventory, gathers the class reference of the filled inventory slot’s object.
  • Remove From Inventory, used to remove objects from inventory slots and update whether or not the slot is free.



Next I went and added the Inventory Component to my character, made the Pick up and Throw events, and a trace function that let the pick up event work.