I had been starting prototyping my actor in blueprints and after I did Actor with StaticMesh and Thruster components as result I got working mesh which is able to move by Thruster.
After that I just tried to implement same thing in C++ class and found that this actor instance not able to moving by native Thruster component (which has same settings that original blueprint Thruster).
Also I had made test by creating blueprint from c++ class anding blueprint Thruster to it, in that case mesh started to moving.
Here is my code:
/** StaticMesh used for the box */
UPROPERTY(VisibleAnywhere, Category=Planet)
TSubobjectPtr<UStaticMeshComponent> BoxC;
/** Thruster force */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Planet)
TSubobjectPtr<UPhysicsThrusterComponent> Thruster;
APlanetActor::APlanetActor(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// Structure to hold one-time initialization
struct FConstructorStatics
{
ConstructorHelpers::FObjectFinderOptional<UStaticMesh> BoxMesh;
FConstructorStatics()
: BoxMesh(TEXT("/Game/Meshes/Box.Box"))
{
}
};
static FConstructorStatics ConstructorStatics;
// Create mesh component for the box
BoxC = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("Box00"));
BoxC->SetStaticMesh(ConstructorStatics.BoxMesh.Get());
BoxC->BodyInstance.SetCollisionProfileName(UCollisionProfile::PhysicsActor_ProfileName);
BoxC->SetSimulatePhysics(true);
BoxC->SetAngularDamping(0.1f);
BoxC->SetLinearDamping(0.1f);
BoxC->BodyInstance.MassScale = 2.f;
BoxC->SetNotifyRigidBodyCollision(true);
RootComponent = BoxC;
/** */
Thruster = PCIP.CreateDefaultSubobject<UPhysicsThrusterComponent>(this, TEXT("Thruster00"));
Thruster->ThrustStrength = 10000.0f;
Thruster->bAutoActivate = 1;
}
Why behaviour of C++ Thruster is different from blueprint Thruster?
Only difference I found it that blueprint component has transform but native don’t (I guess it might be related to this question How to move a blueprint in the editor with a root native scene component? )