Stop runtime on error

Im making a project that needs an actor to find an specific component from certain other actors, and because how unreal engine works the editor crashes if it doesnt have that component (yes even with if (component!=null)) and wnat to know how to make the editor just stop running and throw an error in case that other actor does not have the component.
I have read the assertions documentation but do not understand how ot use it correctly or even if it will help me in this case.

Do you have an example of this code at all, and are you trying to do these things in a constructor?

Assertion is simple, simply call check(bool condition); if it’s false you will get a crash with failed condition in log

As for stoping it, it’s impossible if you can’t prevent check() to be called, you can try to overriding function with them. In log you should find location of where triggered check and try to overriding it if it’s possible.

Note that those assertion checks are code assumptions, it means forward code is not prepared for other condition then defined in the check function, it means even if you gonna override it, the forward code still might have issue with newly introduced condition

UActorComponent* tempTargetComp;
for (int object = 0; object < affectedObjects.Num(); ++object) {
tempTargetComp = affectedObjects[object]->GetComponentByClass(UAROTarget::StaticClass());
check(tempTargetComp != nullptr);
//if (tempTargetComp != nullptr) {
targetAROComponent[object] = dynamic_cast<UAROTarget*>(tempTargetComp);
check(targetAROComponent[object] != nullptr);
//}
}

That is on a function that is called on BeginPlay() but editor still crashes if affectedObjects[object] does not have a UAROTarget component