I’ve created an actor and attached a UDestructibleComponent to it. I have been able to successfully set it to destroy, with the following settings:
// Lastly, create the Mesh component and attach it to the capsule.
InteractableDestructibleMesh = CreateDefaultSubobject<UDestructibleComponent>(TEXT("ItemMesh"));
InteractableDestructibleMesh->SetupAttachment(RootComponent);
// Simulate physics and notify rigid body collision.
InteractableDestructibleMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
InteractableDestructibleMesh->SetNotifyRigidBodyCollision(true);
InteractableDestructibleMesh->SetSimulatePhysics(true);
InteractableDestructibleMesh->SetLinearDamping(2.0f);
InteractableDestructibleMesh->SetAngularDamping(2.0f);
However, I only want to trigger it when I want to. For example:
///*If this is turned on, that means this item can be destroyed at high velocity*/
FVector velocity = GetVelocity();
float speed = velocity.Size();
if (speed > 750.0f)
{
// Set to destructible
// Perform other tasks here, such as deactivate components, destroy attached arrays, etc.
}
I’ve been digging around to find any sort of trigger. However, the API docs located here brings up a 404 error, and I have not been able to find any sort of documentation that would help me with this.
I’ll note that I tried disabling collision, but unfortunately this stops me from interacting with the object at all. I’ve also created a capsule wrapper (root component) and attempted to create physics for it, but it didn’t seem to work.
I’ve never really looked at the destructible actor, but I’m assuming it will start it’s destruction when it takes damage. If this is the case then maybe overriding the ApplyDamage method will allow you to perform some additional logic before actually applying that damage. E.g.
Glad it works and thanks for sharing this for others.
And you’re right, the UE4 naming conventions for bool is bMyBoolName. If you’re interested, there are some more standards here: Coding Standard | Unreal Engine Documentation (I can’t say I follow all of them strictly just out of habit, I still like to prefix my member variables with m_ etc)