Search code examples
unreal-engine4unreal-engine5

How to set a mass of mesh of an actor (Blueprint or C++)?


I'm creating an actor that has a static mesh component. I want to acess that static mesh mass and override it to a variable. I've tried Set All Mass Scale, Set Mass Scale, Set Mass Override. In the last two it asks for a bone name, which I don't understand as I work with a static mesh not a skeletal mesh. None of three seem to do anything. How to set a mesh mass inside of an actor class (preferrably in the costructor) in UE5/4?


Solution

  • Example from here:

    void AYourStaticMeshActorClass::SetMassScale(const float& NewScale)
    {
        if(!StaticMeshComponent) return;
           //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        FBodyInstance* BodyInst = StaticMeshComponent->GetBodyInstance();
    
        if(!BodyInst) return;
            //~~~~~~~~~~~~~~~~~~~~~~~~
    
        // New Scale 
        BodyInst->MassScale = NewScale;  
    
        // Trigger Update! 
        BodyInst->UpdateMassProperties();
    }