After 30 mins of looking around, I found out why it was crashing everytime.
Add another check to see if your “PressurePlate” is a nullptr or not…
float UOpenDoor::TotalMassOfActors() const
{
float TotalMass = 0.f;
TArray<AActor*> OverlappingActors;
if (PressurePlate)
{
PressurePlate->GetOverlappingActors(OverlappingActors);
for (AActor* Actor : OverlappingActors)
{
TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
}
}
return TotalMass;
}