Efficiently Storing Weapons in UE4

Before thinking of any inventory system, I searched a bit on how to store my weapons in UE4.

There was actually at least three possibilities:

  • Classes: The more obvious, but it was impossible to get variables out of it without actually spawning them into an actual object.
  • Actors Objects: The easiest, but making them impossible to fill in an array beforehand, has to be done at runtime, so useless for an Item Spawner.
  • Structs: The most complicated with all the breaking/making stuff, but worked fine… Except that it doesn’t accept Meshes or Textures yet.

My other problem, is that I didn’t wanted to have all those weapons floating in my Content Folders as independent blueprints, I wanted all of them inside arrays for an easier overview.

I actually ended up proceeding this way, as it was required for other things. But in my early prototype everything was stored inside a single Struct containing more Structs. Structception.

 

Overview of my main Struct WeaponLibrary containing several Weapon Structs.
Overview of my main Struct WeaponLibrary containing several Weapon Structs.

 

Breaking the WeaponLibrary Struct inside a blueprint.
This is how it looks like when you break your WeaponLibrary. You get all your weapons as independent Structs, ready to use in your code.

 

Using an Enum to choose which weapon to use.
You can now switch on an Enum containing all your weapons, and set it to be your Equiped Weapons.

 

When you break your EquipedWeapon, you get the same Weapon Parameter Struct as in your library.
When you break your EquipedWeapon, you get the same Weapon Parameter Struct as in your library.

 

This is a very user-friendly method, far more intelligible than the traditional Object/Class blueprints as it involve no CastTo, but way less versatile. Quite nice for a very fast prototyping!