# How to save objects between maps?

**URL:** <https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082>\
**Category:** Blueprint\
**Tags:** reference-blueprint, unreal-engine, UE4, Blueprint, question, items\
**Created:** [August 19, 2019, 11:42am UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082 "2019-08-19T11:42:05Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![nejo.quol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nejo.quol](https://forums.unrealengine.com/u/nejo.quol)\
**Post date:** [August 19, 2019, 11:42am UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/1 "2019-08-19T11:42:05Z")

</div>

Hello, I have a problem:  
I can save any item as I need until the item is unloaded. I get references broken, when I try to add a new object to the existing save file, where I already have items from another part of the map that were previously unloaded.  
I save interactable items (a chest, for example) with values like: the reference to the object, destroyed?, how many things were taken, whether it was spawned, etc.  
I save and load information using the structures in which I have: a reference to the object and the object variables that I need to be saved. What do you do in this situation? How to keep the references to the unloaded items saved?

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 19, 2019, 11:53am UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/2 "2019-08-19T11:53:33Z")

</div>

Are you saving in the game instance?

---

<div class="post-metadata">

**Author:** ![nejo.quol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nejo.quol](https://forums.unrealengine.com/u/nejo.quol)\
**Post date:** [August 19, 2019, 12:08pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/3 "2019-08-19T12:08:58Z")

</div>

Hello, no, in the actor component

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 19, 2019, 12:22pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/4 "2019-08-19T12:22:16Z")

</div>

Well there’s your problem probably 🙂

If you want to save information about the state of the game etc, you can do it in the game instance.

It looks just like a regular BP ( variable yada yada yada ), except it carries on existing between levels.

Works like this:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/b/1/7b11150d2dfb9ab9d4e2f4dfb2cd7cedb4e480c9.jpeg "HTF do I? Use the GameInstance Object in Unreal Engine 4") ](https://www.youtube.com/watch?v=5w594D3qtLs)

---

<div class="post-metadata">

**Author:** ![nejo.quol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nejo.quol](https://forums.unrealengine.com/u/nejo.quol)\
**Post date:** [August 19, 2019, 1:12pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/5 "2019-08-19T13:12:52Z")

</div>

Thank you for the answer. I know what the game instance is, but why do you think it will help?  
Even if I save all objects on the map in the game instance, it will break the existing references of the objects on the other map (just tryied that).  
For example: If I save the reference of the object\_a on the map\_a (the reference I need to load variables in this object later) and then save the object\_b and object\_c on the map\_b I will no longer have the reference to the object\_a - in the new save file I will have reference to the object\_b and c, and the broken (null) reference to the object\_a

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 19, 2019, 1:27pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/6 "2019-08-19T13:27:04Z")

</div>

If these objects ( a, b, c ) are BPs that are written to always load and save their data to and from the game instance, it wont matter which map they are in. Even if it’s a different instance of object\_a, when it begins, it loads it’s status and variables etc from the game instance and carries on.

If you’re talking about BP references ( ie, object\_a has a variable of type object\_b ), and when you change maps these pointers are lost, you can do one of two things:

1. Write object\_a and b so that they cope with this. So when object\_a wakes up it looks for object\_b and connects to it. Same for object\_b

2. Or, you could put them in the persistent level and have the levels the ‘appear’ to load in as just other streaming levels.

---

<div class="post-metadata">

**Author:** ![nejo.quol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nejo.quol](https://forums.unrealengine.com/u/nejo.quol)\
**Post date:** [August 19, 2019, 2:01pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/7 "2019-08-19T14:01:07Z")

</div>

No, I don’t need save reference in the variable a to the variable b. I just need to save the reference of the object a to load its information  
I have tried to save and load the information in the game instance, but the result is the same.  
May be I do something wrong?  
First of all, I collect the information about every object. Then I save collected information and load it again. The references from the first map are broken.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 19, 2019, 2:09pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/8 "2019-08-19T14:09:47Z")

</div>

I just took a quick look, but will get back later with more info ( have to do a few things ). I do notice you’re using a save game, rather than game instance, which we’ve been talking about 🙂 ( although that shouldn’t matter much ).

The save game is what it naturally sounds like, whereas the game instance lives between levels until the end of play.

---

<div class="post-metadata">

**Author:** ![nejo.quol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nejo.quol](https://forums.unrealengine.com/u/nejo.quol)\
**Post date:** [August 19, 2019, 2:21pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/9 "2019-08-19T14:21:24Z")

</div>

Thank you so much for helping me 🙂 I thought you want me to use the game instance to save the information  
The fact is that I want to save information of every object, even unloaded or from another map — exit the game — enter the game again and load the information about objects.  
Now if I save the object on first map, I will have the broken(null) reference to the object on the other map. If I save the broken reference - I cannot load the information about this object when I enter the game again.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 19, 2019, 5:47pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/10 "2019-08-19T17:47:08Z")

</div>

Ok, so looking at it now, I’d say your problem is you’re loading the old save game, and appending it with all the stuff from the current game, and then re-saving ALL that. Then next time you run, you’re loading N lots of save game, where N is the total number of times you played!

Why are you appending? All you need is:

1. Load all objects when you start
2. When you save, overwrite the save game ( don’t append )

Am I missing something!? ( possibly… )

---

<div class="post-metadata">

**Author:** ![nejo.quol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nejo.quol](https://forums.unrealengine.com/u/nejo.quol)\
**Post date:** [August 19, 2019, 6:01pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/11 "2019-08-19T18:01:24Z")

</div>

I need to append because if I create a save file for the first time on the map\_a and then save again on the map\_b I will save only map\_b objects, objects from map\_a will be unloaded (can’t get them from GetAllActorsOfClass). Thats why I cannot rewrite existing save file, I need to add unique object to existing objects and rewrite existing objects if they are on the current map. If the object is from the other map - I will not change it.  
Append is a bad solution, I am goind to go through the save and add only unique objects (dont want to dublicate them)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 19, 2019, 6:10pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/12 "2019-08-19T18:10:06Z")

</div>

Ok, but it’s defintely a big part of your problem I think. It would be good to only have copy of each object, and of course, you can’t store the references to objects, because they’re different every time you run a level.

---

<div class="post-metadata">

**Author:** ![nejo.quol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nejo.quol](https://forums.unrealengine.com/u/nejo.quol)\
**Post date:** [August 19, 2019, 6:13pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/13 "2019-08-19T18:13:45Z")

</div>

I will definitely remove the append, this os not hard 🙂  
But what do I need to do with the references? I can’t solve this problem for a while  
I don’t really want to use the streaming level with every object. How will I hide them when I am on the other streaming level…

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 19, 2019, 7:14pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/14 "2019-08-19T19:14:25Z")

</div>

Hold your horses, let me look at it a bit more, I think the basic concept of what you’re doing is absolutely fine.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 19, 2019, 7:24pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/15 "2019-08-19T19:24:11Z")

</div>

Ok, back again already 🙂

Am I correct in thinking that the save game slot name is the same as the level name?

So you have a slot for each level?

Then the append IS a problem. You only need to make one save game for each level, right?

If I’m playing level 1 and the cube is at X=250, you can save that in the slot. Then, next time I play the game, we see it’s level 1, load that slot, move the cube to X=250. But when I’ve finished playing, the cube is at X=500, we only need to save that. We don’t need the X=250 stuff anymore, it no longer applies. That’s the append problem. With the append, you’re putting more and more in the same slot: X=250, X=500, X=…

Do you see?

( excuse me if I’m wrong, had a long day… )

---

<div class="post-metadata">

**Author:** ![nejo.quol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nejo.quol](https://forums.unrealengine.com/u/nejo.quol)\
**Post date:** [August 19, 2019, 7:39pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/16 "2019-08-19T19:39:01Z")

</div>

Wow, you are really cool, I have never thought about that 🙂  
I don’t use the level name based save slot name and I can’t see any issues in this solution right now  
I can make the slot name from the level name and save the items for each level…  
And I don’t even need to use append, each level will have his own array…  
The player experience, inventory save system can be one-slotted, this is not an issue too.  
You are a genius, I will try this solution as soon as possible

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 19, 2019, 7:42pm UTC](https://forums.unrealengine.com/t/how-to-save-objects-between-maps/454082/17 "2019-08-19T19:42:15Z")

</div>

Ha! 🙂 Great.
