Can't find player

My game was working fine until all of a sudden it crashed and when i had built it again it would crashed on Play. I’m not sure if I accidentally hit a shortcut on my keyboard or what. I pinned the crashing to :

FVector PlayerLoc = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();

so I hid all of these and it stopped the crash but now when I hit play, it stays to the viewport camera but the Player Start icon is there…I’m not sure if I may have deleted something or what. My player BP is there so it didn’t get deleted :confused:

anyone have any ideas? T_T

A crash in that line most likely indicates that something in that chain is null at the time of execution.

You can figure out what it is by expanding that chained call into something like this:

UWorld* world = GetWorld();

if(world)
{
	APlayerController* pc = world->GetFirstPlayerController();
	
	if(pc)
	{
		APawn* pawn = pc->GetPawn();
		
		if(pawn)
		{
			// if we get here we're fine
		}
		else
		{		
			UE_LOG(LogTemp, Warning, TEXT("Oh noes, PAWN is null"));
		}
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("Oh noes, PC is null"));
	}
	
}
else
{
	UE_LOG(LogTemp, Warning, TEXT("Oh noes, WORLD is null"));
}

Now, after this, the fun part starts of figuring out why any of these are null.

At which stage of the startup process are you calling this? E.g. during YourGameMode’s BeginPlay, OnConstruction etc.

Ended up bein a glitch I guess… I had to recreate the project to fix it