Why is TArray.Add() crashing unreal?

Only possibility i see from here is wrong cast or array is set up wrong or something.
If you have crash, check the logs, you got stackdump there and if crash was controlled due error occured which engine detected it should show you error message right before the crash. You can find logs in Saved/Logs

Whenever I spawn a character, I want to retain a reference to him in the room he’s spawned in, so when level streaming unloads that room it also unloads anybody who is inside of it. This runs every time the room is streamed in, it spawns my desired character blueprint, but if I uncomment the last line, whose only job is to update the Room’s list of active characters, unreal crashes when it runs. Is there an obvious problem with how I’m using .Add()?

void UPopulationManager::PopulateRoom(ARoom* room){
	FVector const Location = room->spawnerList[0]->GetOwner()->GetActorLocation();
	AActor* testCharacter = World->SpawnActor(CharacterBlueprint, &Location);
	//room->CharactersInRoom.Add(Cast<AMCharacter>(testCharacter)); //CharactersInRoom is a TArray<AMCharacter*>
}

I have no clue why, but adding a sanity check not only stopped it from crashing, but also made it work properly; thank you :slight_smile:

offtopic: you might want to use “StaticCast” instead of “Cast” in this case, because it is more performant than “Cast” (which is a dynamic cast) and does not preform a check.
your question code does relly on Cast retrieving a valid value anyway so it’s pointless to use dynamic cast in that case