I don’t understand why we don’t need to protect the Actor pointer from being null. Is TArray already dealing with the pointers it stores inside? Elaborate a bit on this if you can or point me in a direction to look for more information.
bool UOpenDoor::IsEnoughMass() const
{
TArray<AActor*> OverlappingActors;
if (!PressurePlate)
{
UE_LOG(LogTemp, Warning, TEXT("There is no pressure plate, nullptr found instead"));
return false;
}
PressurePlate->GetOverlappingActors(OUT OverlappingActors);
float MassCount = 0.f;
for (AActor* Actor: OverlappingActors)
{
if (Actor)
{
UE_LOG(LogTemp, Warning, TEXT("Overlapping actor: %s"), *Actor->GetName());
MassCount += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
}
}
return MassCount >= MassToOpen;
}