How would you go about saving weapon customizations in an inventory?

Hi, I’m creating an inventory system, and I’m struggling to think of a way to save weapon customizations while the weapon isn’t equipped, or is dropped and picked back up, or sold and bought back, etc…

For example if I picked up a barebones weapon, no attachments or camos or anything, and then from my inventory widget I choose to customize the weapon, and equipped a sight (which could have another layer of customizations, such as reticle shape and color) somewhere along the top rail, and a grip somewhere along the bottom rail, a torch at the front end of the bottom rail, changed its camo, etc… while it’s either in my backpack (not just swapping between 2 or 3 weapons on the fly), in my hotbar, or in my hand. I then move it around in my inventory to another slot, such as from my backpack to my hotbar, or from my backpack to a shopkeeper/other player for trade, or drop it on the floor, then the next time it’s picked up and looked at in the inventory or equipped it should have the same customizations as I left it with.

Basically how do I keep a memory of my weapons custom variables that can be changed at runtime while the item isn’t spawned in the world, and is just referenced by a slot in the inventory, and then remember any changes that were or weren’t made when it is next spawned, keeping the ammo in the clip, camo, attachments and their locations and customizations, etc…?

What would be the best way to go about this, keeping it optimized and not spawning an object for each inventory slot that stores the variables (that’s the only way I’ve thought of, but I don’t even think that would work (especially through different levels), and I definitely don’t think it would be optimized having 100’s of objects for each inventory in the world!), bearing in mind it won’t just be weapons that are customizable, other item types could have their own variables that can be changed

Sorry if my explanation made that more complicated than it had to be

1 Like

Hi there,

That’s a very good topic. I haven’t implemented it myself yet, but I would go with an equipment array, an equipment manager component, an equipment UI, an weapon upgrade map, and a weapon upgrade UI, all five communicate with your inventory via UI and also read and write information in your save-load game logic.

That’s is just a brain dump, but might give you insights. Whenever you move a weapon to an equipment slot, the Equipment Manager will “save game to slot” and then will read that weapon and check how many “upgrade slots” are available. Then, from an updgrade UI, you can filter only weapon upgrades from your inventory and send the selected upgrades to the correspondent weapon upgrade slots. That transfer will add values to a map variable, which keys are weapon classes and values are set by a struct of slot index and weapon upgrade class. Finally, the updated map variable is saved to a game slot.

When you begin play with your character, the equipment manager will read the saved game variables: equipment array and weapon updgrade map, and for each weapon, it will spawn and attach weapons to the player and upgrades to the correspondent weapons.

Also, take a look at product configurator demo, available for free at marketplace. I am not quite sure if it can be converted into an in-game configurator. I did a weapon configurator, but i haven’t gone any further with that prototype yet.

Quick start:

My demo:

Here’s a memorable tutorial series that covers equipment UI:

1 Like

These systems get complicated fast.

What I’ve found so far making something similar myself is that, the little details about how you want things to work in your game make a major difference in how you need to set the system up.

I started out by looking at a couple marketplace solutions. They are great, fully featured and all that, but if you want to make just a couple small changes, it can become a nightmare. Perhaps the authors might code things in a way so that things are less tightly coupled but I dunno how much you can do with such a complex system.

The only way I’ve been able to make progress on my own is to get the framework built first just using strings.

A string array to store the weapons and attachments, and all the feedback about what you are doing just print as logs.

This way you dont get overburdened with the extranneous details of stuff like dealing with maps and structs at the same time you are trying to figure out the basic communication pathways, if that makes sense.

Once it works with strings, that’s 90% of the work. From there you just use other things to make the work more efficient or convenient.

Of course I dont mean everything literally like you must not use a map or struct at all, but I think you understand the principle.

I ended up using Uobjects to hold my data and pass it around. It gets put into an array, and the array is held on an actor component. The need for using the component is so that I can easily pass data from, say, the player character to a storage container, and I can do so just with one interface call.

So for a weapon system, a single weapon might be described with a Uobject, and there can be an array inside also to describe what attachments are with it.

You could think of that as the data unit which is used to describe the weapon. You can also have a variable to store what actor class to spawn the weapon as when needed. Data tables come in handy there, but again, just to setup the very basic framework i believe its best to use as few moving pieces as possible.

1 Like

Indeed, this is an advanced topic.