Hi,
I am working on a inventory system and was hoping for a bit of advice about how to store the actual items. Basically, I am trying to figure out if it would be better to store items as an array of a custom struct that has details about the item or as the actual actor that the item represents.
Essentially I have a pickupactor class (extends actor) that describes what the item is that should be picked up. I then have various actual item classes such as a weapon which also extend actor and have various methods to do stuff like shoot etc.
I also have a actorcomponent class called inventory (original I know) that houses an array of the items along with various functions to add/remove and equip or mount onto the pawn etc. I was planning on doing this as an interface but I haven’t got that far yet.
I then obviously have my player class which has an instance of the inventory actorcomponent.
So basically, when the player picks up an item, the pickup actor uses the instagator pawn to call a function in the inventory component to get itself added to the array.
However, what I can’t decide is how to best store the items within the inventory. Initially I was going to use an array of the item actors (i.e. weapon) as it makes it easier to mount and also to use the array as TArray can compare the actors automatically.
But I thought this might be a very costly way of doing it as i’d have to create a load of actors for everything in the inventory even when they weren’t getting used. So I then thought it would be better to create a struct and add it as a property on the pickupactor and then just pass that property to the inventory to store in an array of that struct type, then I can use the info stored in the struct instance to spawn the actor (pickup or item depending on function).
But then this obviously makes adding/removing harder and I’m not sure what to do when it comes to mounting some items on the player, but Im sure they can be fixed.
A final option I considered was to just store the pickupactors, but again that seemed like id be keeping hold of a whole actor object when all I needed was a bit of info (class, image icon, name, size and a few others), just like with using the actual item actor
I have essentially got myself in a bit of a muddle and am hoping for an outside opinion/advice on how best to store items