Cannot change destructible mesh at runtime

Hello everybody,
My company is making an RTS style game and we use destructible mesh components when the buildings is destroyed.
It’s all working fine except when I started using a pool of component instead of spawn and destroy a new one every time a building is destroyed.

The problem is that when I reuse an already used component I cannot change the destructible mesh and neither reset the initial status (I’ve not tried yet to manage this last step by hacking the animation system to reset the status because I first need to be able to switch the destructible mesh, and maybe reset the initial status can be achieved by changing the mesh)

The code I use to spawn the component is the following:

UDestructedBuildingComponent* destructileBuildingComponent = NewObject<UDestructedBuildingComponent>(this, UDestructedBuildingComponent::StaticClass());
	check(destructileBuildingComponent);

	//Disable tick
	destructileBuildingComponent->PrimaryComponentTick.bCanEverTick = false;
	destructileBuildingComponent->PrimaryComponentTick.bStartWithTickEnabled = false;
	destructileBuildingComponent->PrimaryComponentTick.bTickEvenWhenPaused = false;

	//Disable decals
	destructileBuildingComponent->bReceivesDecals = false;

	//Needs to save the component when actor placed in the scene
	AddInstanceComponent(destructileBuildingComponent);

	//destructileBuildingComponent->SetCollisionProfileName(SimulatorCharacterCollisionProfileName_g);
	destructileBuildingComponent->bGenerateOverlapEvents = false;

	//Initially set has hidden
	destructileBuildingComponent->SetHiddenInGame(true, true);

	//Register component in order to be rendered and handled by the engine
	destructileBuildingComponent->RegisterComponent();

	//This works only because TileMap is spawned at the origin
	destructileBuildingComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);

	return destructileBuildingComponent;

And this is the code that is responsible to change the destructible mesh:

UDestructedBuildingComponent* destructibleBuildingComponent = Cast<UDestructedBuildingComponent>(DestructedBuildingPool.GetFreeObject());
	check(destructibleBuildingComponent);
	
	check(buildingTile.GetTile()->BuildingDestructileMesh);
	destructibleBuildingComponent->SetDestructibleMesh(buildingTile.GetTile()->BuildingDestructileMesh);

	destructibleBuildingComponent->SetHiddenInGame(false, true);
	destructibleBuildingComponent->SetWorldTransform(buildingTile.GetTransform());
	destructibleBuildingComponent->SetEnableGravity(true);

	destructibleBuildingComponent->ApplyDamage(100000, buildingTile.GetTransform().GetLocation() + FVector(100.f, 0.f, 300.f), FVector(1.f, 0.5f, -1.0f), 29999.f);

I’ve also tried this one instruction when I release the component and set as free in pool, but it make the game assert and after that crash inside the destructible mesh component because the association between chunks and physics state is not valid any more when setting a NULL destructible component:

//Hide the component and reset status and TODO: disable physics
destructibleBuildingComponent->SetHiddenInGame(true, true);

//Commented because this lead the game to crash
//Disable physics to save CPU performance
//destructibleBuildingComponent->SetDestructibleMesh(NULL);

//Release the object in the pool
DestructedBuildingPool.ReleaseUsedObjectByIndex(index);

Has anybody any hint as how to achieve run-time switching and resetting state of destructible mesh component?
If it’s needed I’m ready to switch to version 4.16 if in that version there’s a way to make it work.

Thanks a lot
Maurizio Biancucci

I have this problem too!

Did anyone figure out a solution to this problem? I can reset the destructible mesh just fine, but the collision seems bugged. So far all the settings seem to be exactly the same as the mesh was before it was destroyed. The collision is completely gone though.