Function when called crashes the editor and game

Whenever this function is called, it causes the whole editor to crash.

void AImpulse_AOEcpp::launchCharactersInArea() {
	UWorld* world = GetWorld();
	TArray<AActor*> ListOfCharacters;
	GetOverlappingActors(ListOfCharacters, TSubclassOf<ACharacter>());
	for (int Actors = 0; Actors < ListOfCharacters.Num(); ++Actors)
	{
		AActor* CurrentActor = ListOfCharacters[Actors];
		ACharacter* CharacterToLaunch = Cast<ACharacter>(CurrentActor);
		CharacterToLaunch->LaunchCharacter((FVector)(0, 0, LaunchPower), true, true);
	}
}

Does anyone have any clue why this is? Because it crashes the editor I can’t try to see whats wrong.

It seems you missed out some null check.

CurrentActor is safe because for loop itself guarded it once from de-reference with invalid index.
Casting on CurrentActor is also safe because casting on nullptr will get nullptr.

However, CharacterToLaunch may fail because not all AActors are ACharacters. In which case some of it would be nullptr. Then attempt to call a function that belongs to ACharacters from non-ACharacters, will crash for sure.

Let me know if this fixed your issue with this:

if(CharacterToLaunch != nullptr)
{
    CharacterToLaunch->LaunchCharacter( FVector(0,0, LaunchPower), true, true);
}
else
{
    UE_Log(LogTemp, Warning, TEXT("Cast failed"));
}

I tried this but it still crashes. I don’t suppose that you have any more ideas?

Nevermind I found the problem. Your solution was correct.

Highly recommended to install editor symbols on the engine as well, so whenever the code crash, it will tell you exact line it crashed. In addition, use DebugGameEditor build for tracking variable values. DevelopmentGameEditor sometimes hides pointer information away, and some code will never breakpoint. If you open up using .uproject, it is default using DevelopmentGameEditor build.