Clearing timers on components at endplay crash?

Struggling a bit with this here, right now I just have this:

void UReturnFireWeakpoint::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	GetWorld()->GetTimerManager().ClearTimer(FireTimerHandle);
}

Which seems to be the right way to clear an object’s timers and things on destroyed or on level change. I noticed my game would sometimes crash with an odd error so I wanted to clear these things when the object was destroyed because the error seemed to be coming from timers not being cleared, but after changing to EndPlay, all of my components cause the game to crash because, I think, they can’t get the world. I could be wrong though.

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000210

UnrealEditor_Engine
UnrealEditor_ACTGDFPS502_9894!UShieldWeakpoint::EndPlay() [EditedToHidePath\ShieldWeakpoint.cpp:59]

The error is for a different weakpoint object, but they all point to the same location which is the same for weakpoints, since most of them just need to clear a single timer.

I’m an idiot. You have to ensure you check the timer handle for validity to prevent this crash. They all seem to be gone now.

Keeping this up in case anyone needs it.

void UReturnFireWeakpoint::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	Super::EndPlay(EndPlayReason);

	if (FireTimerHandle.IsValid() == false)
	{
		return;
	}

	GetWorld()->GetTimerManager().ClearTimer(FireTimerHandle);
}

The call to the base class endplay is just to clear a timer it declares.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.