Ahhh. I spent ages trying to get the code work before Mike showed a solution. I couldn’t work out why the object mass was not being registered. A simple tick in the Generate Overlap Box and my code started working.
This is my code for GetTotalMassOfActors(). I am not entirely happy with it because in the Visual Studio editor it says there is a ‘pointer to incomplete class type not allowed’ but it compiles OK and seems to work.
float UOpenDoor::GetTotalMassOfActors() const
{
float TotalMass = 0.0f;
TArray<AActor*> OverlappingActors;
PressurePlate->GetOverlappingActors(OUT OverlappingActors);
for (AActor* actor : OverlappingActors)
{
TotalMass += (actor->FindComponentByClass<UPrimitiveComponent>())->GetMass();
}
UE_LOG(LogTemp, Warning, TEXT("TotalMass %f "), TotalMass);
return TotalMass;
}
Another issue was the mass of the BP_DefaultPawn. - It seems to have 66kg of mass I can’t account for. Originally I set the mass to 70kg but the debug log shows 136kg. So I set the mass to 0 and it still shows a mass of 66kg. Strange …