In this lecture it is said the pointers “ActorHit” and “PhysicsHandle” could be protected in the following way:
if(ActorHit)
{
if (PhysicsHandle)
{
PhysicsHandle->GrabComponentAtLocation
(
ComponentToGrab,
NAME_None,
GetPlayersReach()
);
}
}
But instead we choose to do it this way with the explanation that this would exit the function ignoring everything after if (!PhysicsHandle){return;}
in case of a null-pointer
if(ActorHit)
{
if (!PhysicsHandle){return;}
PhysicsHandle->GrabComponentAtLocation
(
ComponentToGrab,
NAME_None,
GetPlayersReach()
);
}
Now my question is: Would the first example not also ignore everything within if (PhysicsHandle)
?
Or would it somehow still have some effect on the performance? Or is this preferred because it is easier to read or maybe safer?
And why do we not use it for ActorHit as well?
For example like this:
if (!ActorHit || !PhysicsHandle){return;}
PhysicsHandle->GrabComponentAtLocation
(
ComponentToGrab,
NAME_None,
GetPlayersReach()
);