() returns null in BeginDestroy

I have compiled 4.8 UE (without hotfix). When i compile my editor with my game module and run the game from editor, the game crashes in BeginDestroy() of my player controller class on line where Im getting timer manager to clear my timer. I solved this by adding nullptr check (below).

void AMyPlayerController::BeginDestroy()
{
	//
	if (())
	{
		GetWorldTimerManager().ClearTimer(ObjectTrackingTimer);
	}
	

	//
	Super::BeginDestroy();
}

2 questions:
Why is Destroy called on player controller when the game has just been started?
Why the controller doesnt have its world set when being destroyed?

Ill try to replicate it if needed, I did a quick fix and posted this question later.

1 Like

Here you have the cause why it’s null:

UWorld* AActor::() const
{
	// CDO objects do not belong to a world
	// If the actors outer is destroyed or unreachable we are shutting down and the world should be NULL
	return (!HasAnyFlags(RF_ClassDefaultObject) && !GetOuter()->HasAnyFlags(RF_BeginDestroyed|RF_Unreachable) ? GetLevel()->OwningWorld : NULL);
}

In other words, when object is being destroyed World is inaccessible from that object, because that object stop being part of any world.

1 Like

Thx, I moved the Timer clear to EndPlay.
The first question still stands.

hmmm most likely because engine create PlayerController and destroys it in begining i guess, engine can do that