Saving / loading a bunch of collectible items?

I’m wondering what would be the best way of saving which collectible items have been picked up by players and which ones have not? I spawn around 250 collectible coin-like objects in a level.

The only blueprint friendly method I’ve thought of would be:

  1. when saving: getting the current location every time a player picks up an object, saving that location to an array.

  2. when loading: I’d loop through the array of locations saved in step 1 and check if a collectible item exists at the saved location, and if so, destroy it.

I’m always so worried my methods are unclean, messy or terribly inefficient so I’ve been wondering if perhaps there’s a obvious better way of doing this?

Any kind of tip is greatly appreciated.

Hi,

I would give the Objects an unique id on generation. This could be the object number in world (1, 10, 20, …). The objects have to be the same during the level. I would go this way:

I would need 2 blueprints for this (and possibly a structure to store item data, but this depends on implementation):

  • BP_Item
    => This is the spawned actor
  • BP_ItemController
    => Has a list of all items in world and gives you methods to access them
  1. Generate level with coins and give every coin an unique id and some meta data
    • id, position, type, collected, who collected, …
    • store coins in a array
  2. Player collect an item, set them as collected, destroy actor but the entry remains in the array
  3. Save every coin with meta data
    • id, position, type, collected, who collected it, …
  4. On load
    • Load the list of all items
    • Spawn actors for all not collected items
    • Assign collected items to player(s) if needed
    • Further processing…

Just a few thoughts on it to give a possible direction.

Kind Regards

freakxnet

Thanks thats exactly what I needed.

Would I need to spawn the items after level load (at pre-placed target points for example) to get a unique static ID?

At the moment they’re all pre-placed in the editor. I’m just wondering how to get them to generate always the same static ID, I guess I could expose a variable and set it manually for each instance but that might take a while. Are there any methods to automatically generate a sequential ID while in the editor?

You could use the objects name instead of an id. The name should be unique. Then you have to check against a text instead of number but this should not a problem.

freakxnet

@freakxnet ah, ofcourse. That seems so obvious now. Thank you. :smiley: