Set location of Destructible Component's chunks

Hello ! How to get the skeleton of a Destructible mesh ?
(My final goal is to set the location of the individual chunks, and I think getting the skeleton is the best way to do this, because I have tested to set the locations of the PxActors of the Chunks, and it had awful bugs, the chunks were not at the targeted location. So, if getting the skeleton is not the best way, please tell me)

Thanks !

UDestructibleComponent is derived from USkinnedMeshComponent class. There’s a variable called SkeletalMesh in USkinnedMeshComponent.

That said, to get the location of a chunk, I added this function to the UDestructibleMesh class:

FTransform UDestructibleComponent::GetChunkTransform(const int32 index, bool isChunkInfoIndex /*= false*/) const
{
	int32 chunkIndex = index;
	if (isChunkInfoIndex)
	{
		verify(index < ChunkInfos.Num());
		chunkIndex = ChunkInfos[index].ChunkIndex;
	}

	FTransform returnTransform;

	if (ApexDestructibleActor != nullptr)
	{
		const physx::PxMat44 ChunkPoseRT = ApexDestructibleActor->getChunkPose(chunkIndex);
		const physx::PxTransform Transform(ChunkPoseRT);

		// Get rotation
		FQuat chunkRotation(Transform.q.x,
			Transform.q.y,
			Transform.q.z,
			Transform.q.w);

		returnTransform.SetRotation(chunkRotation);

		// Get location
		const FVector chunkLocation(ChunkPoseRT.getPosition().x,
			ChunkPoseRT.getPosition().y,
			ChunkPoseRT.getPosition().z);

		returnTransform.SetLocation(chunkLocation);
	}

	return returnTransform;
}

Thanks, but, my question was about setting the chunks locations, not getting it. I already know there is a SkeletalMesh variable, but, it is only a reference to the mesh we are using, not its real-time instance :wink:

If you take a look at the function I pasted above, I’m accessing the real time chunk location here:

const physx::PxMat44 ChunkPoseRT = ApexDestructibleActor->getChunkPose(chunkIndex);

I can check later, but maybe look in ApexDestructibleActor for a function to set the chunk pose?

Finally, I found out by myself. Yes, there is a function to set the pose, but it’s not the same way :
First, I have to get the PxActor of the Chunk. Then, I have to set its pose.

// These two lines are from Rama
int32 ChunkCount = DestructibleComponent->ApexDestructibleActor->getNumVisibleChunks();
const uint16* ChunkIdxs = DestructibleComponent->ApexDestructibleActor->getVisibleChunks();

for (int32 ThisIdx = 0; ThisIdx < ChunkCount; ThisIdx++)
{
	FVector NewChunkLocation = GetActorLocation(); // Set whatever you want here

	PxRigidDynamic* PxChunkActor = DestructibleComponent->ApexDestructibleActor->getChunkPhysXActor(ChunkIdxs[ThisIdx]);

	PxTransform ChunkTransfrom = PxChunkActor->getGlobalPose(); // Useless beacause the two properties are overriden
	ChunkTransfrom.p = PxVec3(NewChunkLocation.X, NewChunkLocation.Y, NewChunkLocation.Z);
	ChunkTransfrom.q = PxQuat::createIdentity(); // Rotation has to be zeroed, because otherwise chunks will rotate at a high speed. You can set it, but don't use the actual rotation of the chunk
			
	PxChunkActor->setGlobalPose(ChunkTransfrom);
}

So in order to get the chunks, I need the ApexDestructibleActor, which is always NULL.
Is this ApexDestructibleActor type only available, when I import Apex assets?

How to avoid this NULL problem?

bump, this is an issue. ApexDestructibleActor is null when using destructible mesh