Download

Saving procedural item inventory data

I wonder how one would save an item with random stats to an inventory? IDs arent an option. Is data asset where i should look?

You could use a data asset, but you’d have to make it using “Construct Object from Class” because changing variables on a data asset made in the editor changes the editor asset itself. Though, I don’t know if doing it this way will work in multiplayer because you’re constructing an object.

I would use a struct since it’s really just variables you need for stats. I would make sure to only generate & save the stats on the server; that way, everybody gets the same values from the same place. Making the stats replicated should already do this.

How would you use a struct, when its only attached to certain objects?

If you’re generating the stats on the server, than it’s the same as any other variable, so if it’s replicated, the stats will replicate to everybody. If you’re generating the item on the client, then you can send the stats to the server through a run-on-server event; though, you should generate & store the stats only on the server to avoid cheating.

Where you store the struct is up to you. You can store it in the item actor itself (like a player dropping their weapon when they die), or you can store it in an array/map on the server (useful if there will be more than one of the same item).