"Set Mass Override in Kg" and "Set Mass Scale" Blueprint node don't work.

Pretty much explained in the title. I’ve got a blueprint (parent class Pawn) and I want to be able to switch between different static meshes, each with different properties. One of the properties I want to control is the mass of the objects, as I’m making a physics-based game. I want certain static meshes to be able to knock over obstacles, while others can’t. I tried using the Set Mass Override in Kg node in the blueprint, and it does nothing. Something else I’ve noticed is that when I get the mass of the static mesh in the Pawn blueprint and plug it into a PrintString node, the mass stays at 1.0kg, no matter what. Even if I override the mass of the mesh in the component properties, it stays at 1.0kg. I’ve also tried the Set Mass Scale node and it doesn’t change anything either.

Does anyone know why this is? Any help would be greatly appreciated! Thanks.

Reviving this question. I still haven’t found a solution!

The “Set Mass Override in Kg” node should work. Is “Override Mass” checked?

1 Like

Yes it is. For whatever reason, nothing changes. I think it might have to do with the component and not the node, because even changing the mass override in the component properties (instead of with the blueprint) still results in the mass staying at 1.0kg.

Could you provide detailed steps of what you’re doing. If I:

I get:

  • the small cube is 1kg
  • the large cube is 100kg
  • the ball is 200kg
1 Like

I recently bumped into this problem and found a solution. It needs a bit of C++ know how; it’s a just copy, paste, and build solution (watch a tutorial). It does the job pretty well in my project, so it should work for you too. Wahooney makes no guarantees as to the marketability, usefulness, or stability of this solution, use at your own risk, etc.

UFUNCTION(BlueprintCallable)
static bool SetPrimitiveOverrideMass(
	UPrimitiveComponent* InComponent, 
	const float InMass = 1.0f, 
	const bool OverrideMass = true)
{
	if (InComponent)
	{
		// unlike the built-in function, get the unwelded body instance
		if (auto* BodyInstance = InComponent->GetBodyInstance(NAME_None, false))
		{
			BodyInstance->SetMassOverride(InMass, OverrideMass);

			// update the mass properties on the welded body instance
			// sometimes this is the only one that exists
			if (auto* MainBodyInstance = InComponent->GetBodyInstance(NAME_None, true))
			{
				MainBodyInstance->UpdateMassProperties();
				return true;
			}
		}
	}
	
	return false;
}

image

Hope this helps.

Details for Filthy Nerds

The problem is that the built-in function gets the welded physics body by default and seems to only affect the mass of the primary body. This new function gets the unwelded body, overrides its mass, and updates the welded body mass properties (combined mass, center of mass, etc.) This will be slightly less performant, but if you’re doing this more than once per tick on average you may have other problems. Even once per tick is a bit crazy… What are you even making?

EDIT

The following function gets the mass of a single unwelded body if anyone needs it:

UFUNCTION(BlueprintPure)
	static float GetPrimitiveMass(UPrimitiveComponent* InComponent)
	{
		if (InComponent)
		{
			// unlike the official function, get the unwelded body instance
			if (const auto* BodyInstance = InComponent->GetBodyInstance(NAME_None, false))
			{
				return BodyInstance->bOverrideMass ? BodyInstance->GetMassOverride() : BodyInstance->GetBodyMass();
			}
		}

		return 0.0f;
	}
4 Likes

Thanks! This seems to work :grinning:

1 Like

Apropos of nothing, this is the code to get the mass (the built-in mass gets the welded body mass):

UFUNCTION(BlueprintPure)
	static float GetPrimitiveMass(UPrimitiveComponent* InComponent)
	{
		if (InComponent)
		{
			// unlike the official function, get the unwelded body instance
			if (const auto* BodyInstance = InComponent->GetBodyInstance(NAME_None, false))
			{
				return BodyInstance->bOverrideMass ? BodyInstance->GetMassOverride() : BodyInstance->GetBodyMass();
			}
		}

		return 0.0f;
	}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.