Wrong pawn weight

Why do I receive the wrong weight of the Pawn, while the table and chairs weights are correct?

DefaultPawn_BP/Collisioncomponent/MassInKg = 70

float TotalMass = 0.f;

// find all the overlapping actors
TArray<AActor*> OverlappingActors;
PressurePlate->GetOverlappingActors(OUT OverlappingActors);
// iterate through them adding their masses
for (const auto* Actor : OverlappingActors)
{
	TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
	UE_LOG(
		LogTemp, 
		Warning, 
		TEXT("%s on pressure plate,  mass = %s, actor total mass: %s"), 
		*Actor->GetName(), 
		*FString::SanitizeFloat(Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass()),
		*FString::SanitizeFloat(TotalMass)
	);
}

One Default_Pawn:
LogTemp:Warning: DefaultPawn_BP_C_0 on pressure plate, mass = 119.059105, actor total mass: 119.059105

chair, table and pawn together:
LogTemp:Warning: SM_TableRound_2 on pressure plate, mass = 20.0, actor total mass: 20.0
LogTemp:Warning: SM_Chair_2 on pressure plate, mass = 14.999999, actor total mass: 35.0
LogTemp:Warning: DefaultPawn_BP_C_0 on pressure plate, mass = 119.059105, actor total mass: 154.059113

Is there a way to fix it?

1 Like

I’m wondering the same. My only wild guess is that maybe it’s inheriting some mass from the Pawn class? I could be way off. I’m still a noob.

It happened to me as well and I found a kind of workaround.

What I think it’s happening is that the GetMass() function is adding the mass of all the components existing in the actor. While the chair and the table only have a MeshComponent, the Pawn has a CollisionComponent AND a MeshComponent that is its child, and both components have an independent mass. The problem is that even if the Physics in MeshComponent are deactivated, the GetMass() function uses its mass to calculate the total mass of the actor all the same.

What I did was use the Physics in the CollisionComponent to apply physics and collision to the Pawn and establish its mass, and then set the mass of the MeshComponent to 0 (which the editor sets to 0.001, because something can’t have no mass I suppose), so the total mass of the Pawn appears to be 70.00999 if you print it.

It’s not a very elegant solution, but it’s what I did. I hope this helps someone.

1 Like

Yeah kinda what fixed it for me. Actually you don’t need to set the mass to almost zero, I just checked simulate physics on the MeshComponent and now it’s printing exactly 70.000.

1 Like

Hello Guys,

My problem is probably the same but not sure. I set my pawn weight to 50kg and in the OpenDoor.cpp for open door condition, I have :

114853

But when I go to the pressure plate, even though my pawn weight is only 50kg, the doors are opening but they shouldn’t as required weight is greater than 60kg. Please help!!!

Thanks & Regards,
Bhanu

Privacy & Terms