Engine crash when i try to check if an actor array element isn't null

So, I am trying to make a spawn system to my game so the enemies will automatically spawn when i get close to a target point and only one enemy can be in the scene per target point, but whenever I run the game with this code the editor instantly crashes and I can’t figure out why. I’ve made some tests and the problem is definitely in the SpawnEnemy function, but not bellow the second if.

.cpp file:

#include "CUGameMode.h"
#include "BOTEnemy.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/World.h"
#include "Public/TimerManager.h"
#include "Engine.h"

ACUGameMode::ACUGameMode()
{
	PrimaryActorTick.bCanEverTick = true;
}

void ACUGameMode::BeginPlay()
{
	Super::BeginPlay();
	UGameplayStatics::GetAllActorsOfClass(GetWorld(), SpawnerClass, Spawners);
}

void ACUGameMode::SpawnEnemy()
{
	for (int i = 0; i < Spawners.Num(); i++)
	{
		if (Spawners[i]->GetDistanceTo(Cast<AActor>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))) < 7000.f)
		{
			if (!SpawnedEnemies[i])
			{
				FTransform SpawnerTransform = Spawners[i]->GetActorTransform();
				EEnemyType SpawnedEnemyType = EEnemyType::Barghest;
				if (Spawners[i]->ActorHasTag("BarghestSpawner"))
				{
					SpawnedEnemyType = EEnemyType::Barghest;
				}
				SpawnedEnemies[i] = GetWorld()->SpawnActorDeferred<ABOTEnemy>(ClassToSpawn, SpawnerTransform);
				SpawnedEnemies[i]->TipoDoInimigo = SpawnedEnemyType;
				SpawnedEnemies[i]->FinishSpawning(SpawnerTransform);
			}
		}
	}
}

void ACUGameMode::SpawnerTimer()
{
	bCanSpawn = true;
}

void ACUGameMode::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	UGameplayStatics::GetAllActorsOfClass(GetWorld(), ABOTEnemy::StaticClass(), EnemiesSpawned);
	if (EnemiesSpawned.Num() < 10 && bCanSpawn)
	{
		SpawnEnemy();
		bCanSpawn = false;
		GetWorldTimerManager().SetTimer(SpawnTimer, this, &ACUGameMode::SpawnerTimer, 2.f, false);
	}
}

.h file:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "CUGameMode.generated.h"

/**
 * 
 */
UCLASS()
class CU_API ACUGameMode : public AGameModeBase
{
	GENERATED_BODY()
private:
	virtual void BeginPlay() override;
	FTimerHandle SpawnTimer;
	TArray<class AActor*> Spawners;
	TArray<class AActor*> EnemiesSpawned;
	TArray<class ABOTEnemy*> SpawnedEnemies;
	UPROPERTY(EditAnywhere, Category = "Class")
	TSubclassOf<class AActor> SpawnerClass;
	UPROPERTY(EditAnywhere, Category = "Class")
	TSubclassOf<class ABOTEnemy> ClassToSpawn;
	UFUNCTION()
	void SpawnEnemy();
	UFUNCTION()
	void SpawnerTimer();
	bool bCanSpawn = true;

public:
	ACUGameMode();
	virtual void Tick(float DeltaTime) override;
};

I have made some more tests and now I am sure the problem is in the if on line 25 of cpp file but still cant figure out what is wrong though.

Try Changing line 17 in the .h file from:

TArray<class AActor*> Spawners;
TArray<class AActor*> EnemiesSpawned;
TArray<class ABOTEnemy*> SpawnedEnemies;

To:

UPROPERTY()
 TArray<class AActor*> Spawners;

UPROPERTY()     
TArray<class AActor*> EnemiesSpawned;

UPROPERTY()     
TArray<class ABOTEnemy*> SpawnedEnemies;

Further, do you have a crash log?

That didn’t did it, the editor is still crashing.

Here is the log:
link text

It seems like you uploaded the editor log. Do you have the crash handler open up when the game crashes? The stacktrace in there is what would be needed.

Sorry, the window that pops up when the editor crashes just give me a link to the editor log and says I don’t have debugging symbols required to display the callstrack for the crash.

Just solved it, the problem was that i hadn’t initialized the array, thanks for the help.