SetRelativeLocation crashing game on exit

I have a UObject that implements FTickableGameObject. At every tick, I take an external static mesh component and call SetRelativeLocation on it.

When I exit the game, it crashes with the following message:

Access violation reading location 0xFFFFFFFFFFFFFFFF.

This happens on line 491 of SceneComponent.cpp:

if (Parent && !Parent->bWorldToComponentUpdated)

With the stack trace going back to me calling SetRelativeLocation. What kind of check do I need to put around my code to have this crash not happen? Or better yet, is there any way to automatically stop ticking when the game ends?

The simplest check of course would be

if (StaticMeshComp)
{
     StaticMeshComp->SetRelativeLocation(...);
}

Let’s see if this is enough already. Otherwise write a comment below.

Hey, unfortunately this doesn’t work. I’ve also tried checking if the world of the mesh is null since the crash line seems to be about projecting the new transform to the world or something, but they’re both valid.

It looks like you are trying to reference something that is no-longer there. As suggested by Schdek it is worth testing for a NULL reference, but then also check if it is valid

if (StaticMeshComp && StaticMeshComp->IsValidLowLevel())
{
    StaticMeshComp->SetRelativeLocation(...);
}

In your example it looks like StaticMeshComp would be being set to a non-NULL value (0xFFFFFFFFFFFFFFFF) so the test for NULL will pass, as the value isn’t NULL. The IsValidLowLevel should check that the reference is valid and whatever it points too checks out.

HTH