How to spawn a destructible mesh?

i know how to spawn a static mesh. but how to do it with destructible meshes?

static mesh:
.h:

UCLASS()
class ASolidBlock : public AActor
{
	GENERATED_UCLASS_BODY()
	TSubobjectPtr<UStaticMeshComponent> MyBlock;
};

.cpp:

ASolidBlock::ASolidBlock(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	MyBlock = PCIP.CreateAbstractDefaultSubobject<UStaticMeshComponent>(this, TEXT("SolidBlock"));
	static ConstructorHelpers::FObjectFinder<UStaticMesh>StaticMesh(TEXT("StaticMesh'/Game/Blocks/SolidBlock.SolidBlock'"));
	MyBlock->SetStaticMesh(StaticMesh.Object);
	RootComponent = MyBlock;
}

so when i now want to replace “static mesh” with destructible mesh i have several problems.
in the .h file there is UStaticMeshComponent but no UDestructibleMeshComponent…
in cpp this is also a problem and then a UDestructibleMesh has no function SetStaticMesh…

please help :slight_smile:

Update:

Mesh = ObjectInitializer.CreateDefaultSubobject<UDestructibleComponent>(this, TEXT("CharacterMesh"));

const ConstructorHelpers::FObjectFinder<UDestructibleMesh> meshObj(TEXT("DestructibleMesh'/Game/Mesh/SM_Player_DM.SM_Player_DM'"));

Mesh->SetDestructibleMesh(meshObj.Object);
RootComponent = Mesh;

gives me the error:
1>C:\Program Files\Unreal Engine\4.6\Engine\Source\Runtime\CoreUObject\Public\UObject\ConstructorHelpers.h(92): error C2664: ‘void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)’ : cannot convert argument 1 from ‘UDestructibleMesh *’ to ‘UObject *’

can someone help?

Try adding #include "Engine/DestructibleMesh.h"

Hi

I had managed to get as far as the above poster in their question and found your answer. It helped me get past that error but now when I try to run the debugger it will fail at line 3004 in BodyInstance.cpp with:
check(GEngine->DefaultPhysMaterial != NULL);

Can’t seem to fix that or make it work when setting a physical material either. Any thoughts (or the proper way to set the default physmaterial)?

Docs for DefaultPhysMaterial say: “PhysicalMaterial to use if none is defined for a particular object.”. DefaultPhysMaterial sholdn’t be used if the object already has a PhysicalMaterial.
Try setting that property from editor or see this.