How can I update a blueprint class variable inside an actor and have it save?

Im working on an item and inventory system in which when I pick up items it saves it in an array of object classes.

When I switch to an item it gets that class and all the variables to determine things like mesh, thumbnail, and whatnot.

I also have a variable in the class default that I want to use called “is active” This could be used for something like a flashlight to determine if the light is still no when you store the item away, This way when you take the item back out the light will be whatever you set it to last.

My current issue is that this default variable isn’t updating inside of the class once the actor gets destroyed, so once you spawn the actor in from that class, all the variables go back to default.

Is there a way to update the class? if not what do I do? Also what happens when I need objects like weapons that require ammo? How can I efficiently store and update things like ammo count in these classes?

Use a Struct for each SLOT. The struct will be specific to the Item Type.

Better way to prevent spawning/destroying ( substantial performance hits ) is to store the spawned actor as an obj type ref. Then hide the actor when not in use.

Inventory slots:
weapon1 (class specific obj ref)
weapon2 (class specific obj ref)
flashlight (class specific obj ref)

How can I store information in these structs and have it updated, for example, item charge or ammo left in gun?

You’d store it directly in the items actor class.

Now if I wernt going to destroy or create actors (items), but only hide them when not in use, Since there are 4 players and each player can carry around 10 items, plus however many are left on the map, wouldn’t that eventually get very non performant?

Not if you set everything up to be client/server performant.
“Pick up items” in the world should be small data simplified actors (mesh, interaction collision, identifier ID). You can use a data table to get the class of the real item.

On pickup you destroy the “simple” and spawn the “real item”…Gun, flashlight etc. Attach and hide, or equip to hand.

On drop you destroy the real item and spawn a simple in its place on the ground.


Servers load the entire map and ALL actors. Clients only load a small “relevant portion”. So thinking through this if all your actors in world are heavy…fully coded working guns, flashlights etc. Then the server will need a mega ton of memory. If they are simple actors (mesh, interaction collision, identifier ID), then that’s a lot less memory needed.

Same applies for a client and what it loads.

Also spawning and destroying items as you swap… wep 1 → wep 2 → wep 3 ->, back and forth, is a performance killer. Server has to spawn and attach, detach and destroy for the actions to be replicated. It’s multitudes more performant on both the client and server to simply hide/unhide and attach/detach.

You also gain responsiveness by maintaining the item actors. The client can now switch locally and let the server correct if need be. e.g. switch weapon → rpc server to switch


I’m working on a 100 player MMOFPS. My inventory (Actor Component) uses a “slot based” system for inventory management.

All 3 weapons the character can hold are attached to the body and visible at all times. If the item will be attached to the character I use an actor obj ref.

image

The weapon class has many structs to configure it. Here’s one for example.

image

I have others for recoil, sway, deviation, gravity curves, animations, IK offsets…AMMO (type, max mag, current mag etc)


When a weapon is equipped to use I set the current weapon var. This is then used to call events, pull data as far as ammo, firing mode etc.

Wow! This was very helpful, thanks for sharing!

I should also note that my weapons are customizable.
Grip, Muzzle, Magazine, Optics, Stock, Rail…skin

I use a struct of structs in the “real weapon” class to store data on attachments. This is a Rep_Notify variable.

image

image

In world items for weapons (guns on the ground) I have a struct that holds data table row names. So when a gun is dropped and the attachments are to stay with it I can store refs to those attachments. This makes it possible to drop a fully kitted gun for a team mate to pick up.

image

image


example world item weapon (ground loot)

That makes sense. I was originally watching a tutorial for my inventory where the entire inventory was pretty much composed of a class array. Obviously thats caused many issues, currently looking into structures and how i can best utilize them for my type of inventory.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.