Disappearing Variables

Good day. I have got a strange issue.
I am trying to save into my Game Instance a map variable (Keys - Actor; Values - Structure containing Integer (Health) and Vector (location))

I made 2 functions:
1st: Save All actors of class (BP_Enemy) into my map (Actor as Key, Health and Location as Values)

2nd: Print to Screen all my keys and their health (Integer).

If I am on the same level, and press 1st Function to save to variable and then 2nd function do display, everything seems to be OK. It display name of the Enemy, and his health.

BUT, here is the interesting part: When I open new level and press 2nd function which just print keys and values, it doesnt print Keys (All keys are EMPTY - Which is imposible for Map variable) and print only some default Health values.

How is possible to MAP just lost all its Keys?
This variable is in Game Instance, It shouldn’t be affected by opening new level.

Actor references aren’t the same between different levels.

There’s no guarentee they will be the same with repeated runs on one level. Which is why they’re not a good way to save information.

One way around this is to give each actor an ID. It can be just an integer.

1 Like