How would one design a system where Items (Actors) in the world can be picked up and thus permanently deleted from the level and added to the inventory. This deletion needs to persist a restart of the game. I`m thinking of Item-systems like the ones in Fallout here. The way i see it, i have two options:
- save the level at runtime (which will involve c++ i`d imagine)
- spawn every Item dynamically from some huge list after the level has finished loading
Are there other ways, and how could i efficiently construct such a system? If i were to dynamically spawn every Item in the world, this could have a big impact once i spawn tens of thousands of items, equally, if i save the level, it becomes unusable for any other players with different SaveGames. Both ideas have problems so i`m wondering if anyone has experience with those kind of systems and could help me out here.
I’d recommend checking out some of the tutorials for a standard inventory system to get a baseline for what you’re looking for.
You’ll basically want a data structure that holds all of the data that makes an item (id,name,description,icon,stats,meshes,etc). That data structure can be passed to an actor in a level when spawned and then be given to the player when they interact with the item. Your inventory item will essentially be the data structure and the actor will just be a stage that handles how the item is interacted with. From there you can use the basic save game class to store everything you need. You might need to create mutlitple classes but you’ll be able to save locations, items state, etc…within that class.
I’m not at my device right now but I’ll have screen shots if needed later.
I hope this helps!
Hello Entropikz and thank you for your quick answer,
however i was looking for a more abstract way on how to do this. The inventory system i have works fine and is not the problem here. For most items i just store the class itself so i can get the info of it and spawn it when needed. This however only works for generic items of a same type. I would get problems once i want to save weapons, since the weapon system shall be very complicated and due to some systems, the weapon specific data is stored on the weapon itself. With many weapon classes that do different things and unique weapons that are different altogether, it would become unfeasible to, copy the whole data of the actor in a struct. As i understand it, you only save references in your SaveGame and not the object itself, which means weapon dont survive a game reboot.
Now you seem to suggest, that one would dynamically spawn every item in world after begin play, so option 2. This also would be my preferred way, yet i feel this system is limited in some way. How does Bethesda do it with their games? I only found some clues but no definite answer.
The whole system will become quite messy, as you cant place an item in the world for picking up, but rather place a placeholder and then add the item in some big list or array, OR one would save the placeholder state (picked up or not), save those and initialize every item on begin play(let them spawn a random item e.g.). In either way i would need to iterate over every item in the map on begin play. That doesn’t seem efficient to me.