# Trying to access TMap data from SaveGame object is nullptr

**URL:** <https://forums.unrealengine.com/t/trying-to-access-tmap-data-from-savegame-object-is-nullptr/427229>\
**Category:** Editor Scripting\
**Tags:** savegame, loading, level-load, unreal-engine, CPP, question\
**Created:** [June 12, 2018, 6:04pm UTC](https://forums.unrealengine.com/t/trying-to-access-tmap-data-from-savegame-object-is-nullptr/427229 "2018-06-12T18:04:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [June 12, 2018, 6:04pm UTC](https://forums.unrealengine.com/t/trying-to-access-tmap-data-from-savegame-object-is-nullptr/427229/1 "2018-06-12T18:04:59Z")

</div>

I am having a problem when trying to use the SaveGame class. I created a custom SaveGame class, that has a member of type “TMap”, which I use to store information about the previous object game state in a struct. I have tried adding objects to the map and it seems to be working fine, as long as I am in the same scene. When I try to access one of the members of the map after loading a new scene (or in my case, the same scene), I get a nullptr when trying to use the same keys to access the maps I made in the previous scene i.e. ContainerIsStored will return false and if I remove it before trying to access the map, the game will crash. Any idea why this may be? Thank you in advance!

```
// Items stored when saving and changing levels, that need to be reinstantiated
TMap<FString, TArray<FInventoryObjectsStruct>> m_containerItems;

bool UMySaveGame::ContainerIsStored(FString l_containerID)
{
	if(m_containerItems.Find(l_containerID) == nullptr)
	{
		UE_LOG(LogTemp, Error, TEXT("Failed to find container in map!"));
		return false;
	}
	return true;
}

```

---

<div class="post-metadata">

**Author:** ![phil\_me\_up](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phil\_me\_up](https://forums.unrealengine.com/u/phil_me_up)\
**Post date:** [June 12, 2018, 6:28pm UTC](https://forums.unrealengine.com/t/trying-to-access-tmap-data-from-savegame-object-is-nullptr/427229/2 "2018-06-12T18:28:24Z")

</div>

A couple of thoughts about this:

- You have a TMap where the value is a TArray. I know that’s technically supported, but I don’t think it is when the variable has a UPROPERTY specifier
- You don’t have a UPROPERTY specifier (at least not one I can see, but if you did I expect it would error out). Again, I think this is required in order to save the data unless you have some custom logic to serialize / deserialize the data to the TMap on load.

If the problem is the fact you can’t have a TArray in a TMap, then perhaps you should look at having a struct as the value rather than TArray. (e.g. TMap. The Struct can contain a TArray.

Sorry if that’s no use - just going off a hunch.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [June 12, 2018, 7:34pm UTC](https://forums.unrealengine.com/t/trying-to-access-tmap-data-from-savegame-object-is-nullptr/427229/3 "2018-06-12T19:34:08Z")

</div>

This has helped already - I didn’t have it as a UPROPERTY() and the hot compile complained that I cannot use nested containers. Thanks! When loading, I no longer get a nullptr. However, it seems that my map is getting erased when I load a new level.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [June 12, 2018, 7:45pm UTC](https://forums.unrealengine.com/t/trying-to-access-tmap-data-from-savegame-object-is-nullptr/427229/4 "2018-06-12T19:45:22Z")

</div>

My second problem was because some of the members of the struct(s) I was using were not a UPROPERTY as well.
