Fixed a Continuous Crash Issue with OpenDoor.cpp, figured I'd share!

Hi everyone! So after completing the video on Using GetTimeSeconds(), my editor would crash as soon as I hit play. It didn’t take long to realize that it was the last addition - checking if enough time has passed to close the door then calling CloseDoor() - that was causing the crash. I’m not sure why, but I guess since the door is already at its closed rotation, it would cause the editor to crash.

To fix this issue, I added a safeguard by including a “DoorIsOpen” bool as private, setting it to false by default, toggling it when Open and CloseDoor() are called and having the TickComponent check for that too in the condition for closing the door. I figured I’d share it for posterity or in case anyone is suffering in silence and not being able to figure it out.

if (GetWorld()->GetTimeSeconds() - LastDoorOpenTime > DoorCloseDelay && DoorIsOpen)
{
	CloseDoor();
}

I think that should illustrate the important part of my fix, but if the rest of it is needed/suggested, I’ll gladly include it on here.

After posting this last night it bothered me a bit that I couldn’t quite explain why the editor kept crashing on making the door open. Upon further testing this morning, I discovered the problem happened when stepping into the trigger volume as well. Turns out I wasn’t properly assigning the door as Owner because I was declaring a new AActor* Owner within BeginPlay().

This was the actual fix and what I did and documented above was entirely unnecessary. Yay for coding with pointers while exhausted. :slight_smile:

2 Likes

Your boolean does have a beneficial side effect though… It might not be noticeable in a project this small, but you’re saving CPU. Without the boolean, it will continuously run through the close door function. Your boolean prevents the entire function from running unless it’s necessary due to the door being open. :wink:

1 Like

Hahaha, thanks! Yep - after all this I was thinking just that, told myself I’d look it up as I was pretty sure it was a liiiiiittle less computationally expensive to have the script check the bool on tick rather than run the function on tick one way or the other. Thanks again! :slight_smile:

1 Like

Privacy & Terms