When creating a game that has a large number of objects – for example pickup actors in the world (e.g. apple, stick, rose, etc.) – what’s the best way to organize all these items? Each object would have an actor, bitmap representation for display in an inventory bag, weight, how it can be used, etc. Would a database be best or is there a better way of managing these items in Unreal?
In addition say each pickup can be dropped by a player at any point in the game. How is the best way through Unreal to keep track of the pickup object location? Database access through the server seems to be the best way or does Unreal have such a facility or better way to do this built in?
Sounds like you want to use an enum?
There are many ways of doing this.
If it is an online game with a persistent world, you HAVE to store it in a database and provide it as network data on map load.
If it’s a single-player game, or if it spawns a level “fresh” for each load (like an FPS) then you can do a bunch of other things:
- place each item as a blueprint instance in the level file
- load a CSV file that described each item; using code or blueprints
- create an actor whose job it is to populate these items
Note that, for a “MMO” style world, you typically don’t place the items themselves, but “item spawners” that re-spawn items X amount of time after the last item was picked up.
(This means that picking-up-the-item has to notify the spawner, so items need a reference to their-spawner-if-known, which would be NULL after picked up and dropped again)
Separately you probably want to destroy the Actor for the item when picked up, and instead create a simple struct (record) for the inventory item.