Everytime i add “SetMassOverrideInKg” to my code, to change the mass of an object, the engine crashes immediatly on launching, when i open the same projekt again.
Happend to two of my projects now. Any help ?
How are you using the SetMassOverrideInKg function in your code? What kind of component are you calling the function on? Could you post the code class where SetMassOverrideInKg is being called?
here is the code, i just created a new actor. The header file is unchanged. As soon as i save this, compile it, and restart the project, it crashes.
// Fill out your copyright notice in the Description page of Project Settings.
#include "Godless.h"
#include "Test.h"
// Sets default values
ATest::ATest()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
//Setup the mesh
UStaticMeshComponent* mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
ConstructorHelpers::FObjectFinder<UStaticMesh> VisualAsset(TEXT("/Game/BasicShapes/Cylinder"));
if (VisualAsset.Succeeded())
{
mesh->SetStaticMesh(VisualAsset.Object);
mesh->SetSimulatePhysics(true);
mesh->SetMassOverrideInKg("", 1.0);
}
}
// Called when the game starts or when spawned
void ATest::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ATest::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
I believe the cause of the crash is the empty BoneName string. In this case there is no way of knowing what bone is being referred to so the editor doesn’t know what to do with the function call. If you make the same function call on a skeletal mesh (rather than static mesh) and specify a specific bone in the call there should be no crash.
If you make a blueprint based off of your class and select the static mesh component, there is a checkbox in the details panel that will override the mass and allow you to set the mass you want the mesh to have. You can change the mass per instance of the static mesh after placing it in the level in the same way.
So is there no way to set static mesh Mass manually through blueprints (Say adding mass overtime)? Because Im creating containers that actually become heavier as things are added to it.
Using the static mesh as the target you can add a Set Mass Override in Kg node and set the new mass. Be sure to also check the box for Override Mass so that the value that you set will be recognized.
Actually I’m looking into this problem as well, but then in C++. The crash only happens when you first start the engine with a SetMassOverrideInKg in the constructor.
If you add the SetMassOverrideInKg after the engine already started, then there is no problem.
This is the SetMassOverrideInKg function:
if (FBodyInstance* BI = GetBodyInstance(BoneName))
{
WarnInvalidPhysicsOperations(LOCTEXT("SetCenterOfMass", "SetCenterOfMass"), nullptr);
BI->bOverrideMass = bOverrideMass;
BI->MassInKg = MassInKg;
BI->UpdateMassProperties();
}
Not sure about the WarnInvalidPhysicsOperations, but then it goes into UpdateMassProperties, which goes directly into GetSimplePhysicalMaterial, which gives the problem:
check(GEngine->DefaultPhysMaterial != NULL);
and there’s the error. So it seems that there is no DefaultPhysMaterial set in the GEngine when you start the engine. I don’t know if this is a bug, but I’ll report it anyway.
A temporary solution would be to not call the SetMassOverrideInKg in the constructor, but rather in BeginPlay or something like that…