I’m using level streaming so I have a persistent (mostly empty) level and many other levels. I can click a button to travel (load and unload) between these levels.
When I pick up an item from a level, the item is destroyed. Then I travel to another level and pick up an item there. When I go back to any of these levels I want to destroy the previously picked up items.
I already have a saving system implemented and my first attempt was to save each picked up item display name in an array, and when loading, destroy them.
This worked… except for the fact that I can have the same item name in multiple levels. So picking up “Item1” in one level, it would destroy all the items with the display name “Item1” in every level.
I also tried to create and set a unique ID for each item in the event construct using GUIDs.
The problem here is that GUIDs are not persistent and are created on every load of the level.
It’s much easier for the pickups to decide this for themselves, by the way, but…
MyPickup was picked up in level ‘Mylevel’, so the array at index 15 ( say ) has ‘Mylevel/MyPickup’
If the player goes back to MyLevel, the ‘MyPickup’ can see that in the array and destroys itself.
But in ‘MyOtherLevel’, the pickup looks for the combination ‘MyOtherLevel/MyPickup’, doesn’t see it, so remains.
It’s up to you how you how do the IDs, but each type of pickup can have an int ID, or a name etc. If there’s only one of each class, the you can use the class, and so on.