Hi, I’m very new to unreal engine, so I have a simple question. I’m trying to enable physics on a object that has mesh loaded in the constructor, this is the code I use (based on tutorials):
// Sets default values
AShape::AShape()
{
// 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;
UStaticMeshComponent* shape = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Shape"));
RootComponent=shape;
static ConstructorHelpers::FObjectFinder<UStaticMesh> shapeAsset(TEXT("/Game/Shape01"));
if (shapeAsset.Succeeded())
{
UE_LOG(LogTemp, Warning, TEXT("Asset found"));
shape->SetStaticMesh(shapeAsset.Object);
shape->SetRelativeLocation(FVector(0.f, 0.f, 0.f));
shape->SetSimulatePhysics(true);
shape->WakeRigidBody();
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Asset NOT found"));
}
}
The mesh is properly loaded, but physics is not enabled. I can still enable the physics manually in the editor, and then it works, but I create objects like these procedural I cannot rely on that. Any idea what i’m doing wrong? Thank you!