Hello! I have an actor that I wish to collapse into parts when destroyed.
Currently the parts are attached like this:
||TurretMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(TurretMesh));|
|---|---|
||TurretMesh->SetupAttachment(RootComponent);|
If I set the static mesh to simulate physics and blockall in the settings of a child blueprint, the asset detaches and falls to the ground as expected.
So I tried to do the same in C++, but had no luck:
||FDetachmentTransformRules DetachRules = FDetachmentTransformRules::KeepWorldTransform;|
|---|---|
||TurretMesh->DetachFromComponent(DetachRules);|
||TurretMesh->BodyInstance.SetCollisionProfileName(TEXT(BlockAll));|
||TurretMesh->SetSimulatePhysics(true);|
||TurretMesh->WakeRigidBody();|
||TurretMesh->AddImpulseAtLocation(FVector(0,0,1) * 20.0f, GetActorLocation());|
It detaches, but it does not simulate physics, what am I missing?
Edit: Figured it out, turns out I shouldn’t be using BodyInstance.