Saving/Loading Actors

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.

How would you address this problem?

1 Like

The ID is fine, actually, but a different data structure might help.

You can save the level name and ID in an array, and check that? ( could be parallel arrays, or an array of structs ( level name / ID ).

Let me understand what you mean. I save the item’s level name and their GUID. But then, when I load, how would I know which item has which ID?

They are like brand new instances of the class “Item” so they have a different ID.

1 Like

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.

1 Like

I actually tried this as my 2nd attempt but I think it did not work because I used maps. And maps have unique keys.

In my case, the keys were the IDs of the item.

I’ll try again with 2 arrays or using a struct somehow.

Worked like a charm. All I had to do was to replace my map with a struct🤦‍♂️.

You know how I feel right now?
There’s that famous quote: “99% of gamblers quit right before their biggest win”

:skull::skull::skull:

1 Like

:rofl:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.