Best way to deal with missing component?

What is the best way to deal with missing required components (or any other “fatal” errors for that matter)?

Since the Grabber requires a PhysicsHandleComponent, what is the best way to deal with it? It feels that having to check for a nullptr everytime feels error prone (too easy to forget to check), moreover, there is no point running the game/simulation in that case.
One could use a Fatal ulog message in BeginPlay, but crashing the editor is not convenient either, and even dangerous is there is unsaved work.

I found some macros (check, verify, …) but they also causes crashes of the whole editor instead of just stopping the game/simulation.

Is there anything better?

You can have the physics handle be a subobject of the grabber.

// In constructor
PhysicsHandle = CreateDefaultSubobject<UPhysicsHandleComponent>(TEXT("PhysicsHandle"));

… I guess that’s one way to interpret my question :stuck_out_tongue:
What I really wanted to know is, as a “component developer”, how to deal with errors from the “game developer”.

A better example would be a button that needs a reference to the door it will open. How do I tell the game developer that something is wrong and must be fixed, without either having to deal with the error scenario in every single places in my code (if I use error messages), nor by making his unreal editor explode (if I use fatal errors).

Oh right. In that case I would use the macros. To not close the editor I only know of


You could create a function like

void LogError(const FString& Message, UObject* WorldContext, APlayerController* Controller)
    UE_LOG(LogTemp, Error, TEXT("%s"), *Message)
    UKismetSystemLibrary::QuitGame(WorldContext, Controller, EQuitPreference::Quit, false);

Unfortunately, QuitGame does not exit the game immediately. For instance, Tick is still executed after calling QuitGame in BeginPlay, and thus can still cause a crash if one doesn’t check the validity of the pointers/objects.

So, I guess checks everywhere are required, or the editor must crash.
Still, if using checks, QuitGame can at least allow the game to quit early to investigate the problem instead of letting it run forever with some features mysteriously not working.

Thanks for the info.