Hey all! Trying to sort out the best place to store my character’s Inventory Array. Way back in 2014 Epic released an Inventory tutorial series and if I remember correctly they stored the inventory array in a widget blueprint. Then in 2015 they did an updated version for 4.8+ and he said it would be better to store the array in the Player Controller (or Player Character, don’t remember) because the array would be lost if the player died… I’ve always stored them in the player character, but recently I’ve been seeing a lot of people saying they create an actor bp to handle everything, and spawn it in the world with the player… What would be considered best practice? Any input is welcome!
Theres a thing you need to consider:
Should the inventory be remain full if the player dies and respawns?
If so, you need to use one of the persistent classes:
GameState or PlayerState (GameMode works, too if you’re making a single player game)
They are replicated and exist on every client, but won’t get destroyed (PlayerState) when the player dies.
If the inventory should be destroyed when the player dies, use the Pawn class you’re using.
I don’t recommend using the Controller for this.
Generally I agree with what you’re writing but it would be interesting to know why you don’t recommend the controller.
Is this why you’re not recommending the controller? A good multiplayer inventory doesn’t let one client know about other client’s inventory anyway. So a class that exists on all clients is not necessary. Only one that exists on both the server and the owning client.
I prefer the PlayerCharacter aswell if you don’t need it to remain after the player death like Raildex said. I don’t like to use actors for anything that doesn’t require a transform but this might be a nice choice if you want it to be usable in multiple projects.
Thank you guys for your replies. Yes, I am setting up a system that would require the inventory to stay when the character dies. The game will be networked, and character will be equipping items from inventory array to an equip array stored in the same bp. Another place I’ve heard people putting it is the GameInstance because arrays are cleared on servertravel and changing maps. I have always used a save game to save and load the arrays before and after loading a new map/servertravel.
*looking into more about PlayerState