How to get the actual FCollisionShape data from a mesh/model?

Hello,

I’m trying to do a SweepSingleByChannel() that takes in consideration the position and rotation of a mesh, but apparently, there’s no built-in way to do that.

The default UPrimitiveComponent::GetCollisionShape() is:

FCollisionShape UPrimitiveComponent::GetCollisionShape(float Inflation) const
{
	// This is intended to be overridden by shape classes, so this is a simple, large bounding shape.
	FVector Extent = Bounds.BoxExtent + Inflation;
	if (Inflation < 0.f)
	{
		// Don't shrink below zero size.
		Extent = Extent.ComponentMax(FVector::ZeroVector);
	}

	return FCollisionShape::MakeBox(Extent);
}

Any idea how I could get the collision data that is generated on the editor and use it there?

I’ve tried to look into PhysX, couldn’t progress much (it’s a whole new world and I’m not used to it!), but I found a question without answer that would probably solve my problem.

Any idea how can I do this? Thank you very much in advance! :slight_smile:

Update:
I can’t edit the thread title, sadly. It was supposed to be “How to get the actual FCollisionShape data from a mesh/model and do a Sweep with it” :frowning:

FCollisionShape cannot represent mesh collision data. It is only used to represent the simple shapes box, capsule, line and sphere.

Did you consider using UWorld::ComponentSweepMulti instead? It allows you to pass in a UPrimitiveComponent* which will be used to supply the swept geometry. Although the function comment says “Transform of this component is ignored” so if you need this you’ll also have to pass in an appropriate Quat or Rotator to use for the PrimitiveComponent. If you also need to take position into account you can probably simply calculate an offset by which to translate the Start and End points.

Hello,

Thank you for your reply!
I didn’t consider it because I was having all sort of issues with ComponentOverlapMulti(), where it never collided.

Now I hacked this code together (it’s kinda ugly, but it’s late here and I’m tired - but I’m not able to keep this off my mind right now :frowning: )


	FComponentQueryParams ComponentQueryParams(FName(TEXT("Update Sweep")));
	ComponentQueryParams.bTraceComplex = true;
	ComponentQueryParams.bTraceAsyncScene = false;
	ComponentQueryParams.AddIgnoredActors(ActorsToIgnore);

	GetWorld()->DebugDrawTraceTag = "Update Sweep";
	TArray<FHitResult> ResultArray;

	GetWorld()->ComponentSweepMulti(
		ResultArray,
		ManipulatedBlock->BlockMesh,
		CameraLocation,
		BlockPosition,
		BlockRotation,
		ComponentQueryParams
	);

But [FONT=Courier New]ResultArray is always empty. Also, [FONT=Courier New]GetWorld()->DebugDrawTraceTag shows no debug traces.
(The same was happening with ComponentOverlapMulti, but the “non component” version of the functions seems to be working).

Anything else I should do?

Upon adding to DefaultEngine.ini


[Core.Log]
LogCollision=verbose

I got:


LogCollision: ComponentSweepMulti : (BP_Block2x3_C_0.BlockMesh SM_Block_2x3) No physics data
LogCollision: FBodyInstance::OverlapMulti : () No physics data

So I changed [FONT=Courier New]bAlwaysCreatePhysicsState on my mesh to true and this solved the problem!

Thank you! :smiley:

can couldn’t figure out how you solve the problem?

can you explain more plz?

Do you success use actual shape of the mesh for the sweep trace?