Spawned Actor pointer to a TMap

I’m trying to spawn an actor (AChunk) I’ve got that working then i try to assign the returned pointer to a TMap but get a null crash even with the problem line being inside a null check. I’m just at a loss as what to do.

This is the crash report.

Assertion failed: Pair != NULL [File:E:\Programme files\Unreal Engine\4.6\Engine\Source\Runtime\Core\Public\Containers\Map.h] [Line: 471] 

ChunkManager.h

#pragma once
#include <functional>
#include "GameFramework/Actor.h"
#include "ChunkManager.generated.h"

/**
 * 
 */

USTRUCT()
struct FVectorInt2
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY()
	int32 X;

	UPROPERTY()
	int32 Y;
	
	bool operator<(const FVectorInt2& ph) const
	{
		return (ph.X < X || (ph.X == X && ph.Y < Y));
	}

	bool operator==(const FVectorInt2& ph) const
	{
		return ((X == ph.X && Y == ph.Y));
	}

	FVectorInt2& operator=(const FVectorInt2& ph)
	{
		X = ph.X;
		Y = ph.Y;
		return *this;
	}

	
	friend int32 GetTypeHash(const FVectorInt2& ph)
	{
		
		return ((ph.X) + (32 >> ph.Y));
	}


};


UCLASS()
class LOSTONARRIVAL_API AChunkManager : public AActor
{
	GENERATED_UCLASS_BODY()
	
	UPROPERTY()
	int16 MinRadius;

	UPROPERTY()
	int16 MaxRadius;

	UPROPERTY()
	float Timer;

	UPROPERTY()
	TArray<FVectorInt2> MaxChunkLoad;

	UPROPERTY()
	TArray<FVectorInt2> MinChunkLoad;


	TMap<FVectorInt2, AActor*> LoadedChunks;
	
	UPROPERTY()
	FVectorInt2 Temp;

	virtual void BeginPlay() override;
	virtual void GenerateChunkLists();
	virtual void SpawnChunks();
	virtual void SpawnChunk(FVectorInt2);
	
	template< class AChunk >
	AChunk* SpawnActor(FVector const& Location)
	{
		return (AChunk*)(GetWorld()->SpawnActor(AChunk::StaticClass(), &Location));
	}
	

	

};

ChunkManager.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "LostOnArrival.h"
#include "Chunk.h"
#include "ChunkManager.h"


AChunkManager::AChunkManager(const class FObjectInitializer& PCIP)
	:Super(PCIP)
{
	MinRadius = 4;
	MaxRadius = 32;
}

void AChunkManager::BeginPlay()
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "started");
	Super::BeginPlay();
	AChunkManager::GenerateChunkLists();
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::FromInt(LoadedChunks.Num()));
	AChunkManager::SpawnChunks();
	
	
}


void AChunkManager::GenerateChunkLists()
{
	for (int x = -MinRadius; x <= MinRadius; x++)
	{
		for (int y = -MinRadius; y <= MinRadius; y++)
		{
			if ((x * x) + (y * y) <= MinRadius * MinRadius)
			{
				Temp.X = x;
				Temp.Y = y;
				MinChunkLoad.Add(FVectorInt2(Temp));
			}
		}
	}
	for (int x = -MaxRadius; x <= MaxRadius; x++)
	{
		for (int y = -MaxRadius; y <= MaxRadius; y++)
		{
			if ((x * x) + (y * y) <= MaxRadius * MaxRadius)
			{
				Temp.X = x;
				Temp.Y = y;
				MaxChunkLoad.Add(FVectorInt2(Temp));
			}
		}
	}
}

void AChunkManager::SpawnChunks()
{
	for (FVectorInt2 &i : MinChunkLoad)
	{
		if (!LoadedChunks.Contains(i))
		{
			
			

			AChunkManager::SpawnChunk(i);
			
				
		
		}
	}
}


void AChunkManager::SpawnChunk(FVectorInt2 ChunkLocation)
{
	 
	UWorld* const World = GetWorld();
	if (World)
	{
		FVector SpawnLocation;
		SpawnLocation.X = 200*ChunkLocation.X; //change value to 32000
		SpawnLocation.Y = 200*ChunkLocation.Y; // "  "  "   "   "   "
		SpawnLocation.Z = 0;
				
		AChunk* Temp = SpawnActor<AChunk>(SpawnLocation);
		
		
		if (Temp)
		{
			
			
			LoadedChunks[ChunkLocation] = Temp;
			
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::FromInt(LoadedChunks.Num()));
		}
		
		

	}
}

I’m sure i’m just making a simple mistake somewhere, thanks in advanced for any help.

It seems your LoadedChunks doesn’t have ChunkLocation key.

I would try change

LoadedChunks[ChunkLocation] = Temp;

to:

LoadedChunks.FindOrAdd(ChunkLocation) = Temp;

yes that was it thank you, i wouldn’t of thought that was the problem