Per poly skeletal/skinned mesh collider

I know mesh colliders are expensive, but there is absolutely no way around us using them. We need it. For a static mesh, it is easy enough. But we need it for a skeletal mesh as well. I know the skeletal mesh in its current pose is kept on the GPU, so there isn’t easy access directly to it. But we have actually done this in Unity as they do have pretty simple ways to do so. Essentially you copy the base mesh, usually in the T-pose, then run the verticies through the animator. Though a mesh is set up more straight forward in Unity, I was hoping to do something similar using UE4. How should I go about doing this.

Thanks for the help!

I’m not sure about per-poly skinned mesh collision, but there should be a way to get at the vertices on the CPU rather than the GPU. In UE3 there was simply a flag on the SkeletalMeshComponent called bForceCPUSkinning (or something like that). I can’t find a similar flag in UE4, but it looks like there are some functions that may give you what you want.

VertexBufferGPUSkin.SetNeedsCPUAccess - you may be able to call this on the top LODModel and then get access to the verts.
Or you could subclass USkeletalMeshComponent and return true from ShouldCPUSkin, but that might only work in the editor.

Once you have the posed verts, you may be able to create a StaticMesh and then use that for collision. Of course, this approach would be slow (you’d have to re-create that static mesh each frame of the animation) but if this is for an editor tool it would likely be fast enough.

This is actually supported. You can turn it on for each individual skeletal mesh with the Enable Per Poly Collision option in the editor. This will of course be more expensive, but if you need it it should work.

Let me know if you run into any problems with it

Is there an easy way to draw the collider? We are trying to test with the actor’s cursor over delegate, and it isn’t even sort of accurate.

pxvis collision will draw what the physics engine sees. However, this will only draw simple collision like convex mesh and other simple geometry like cubes/spheres.

In the case of per poly (and triangle meshes in general) it will not draw anything. Is it not accurate when using per poly collision?

Even when we have a player controller that has a capsule component running into the mesh collider, it will collide inaccurately. We can go through the leg of the mesh, for example. We even changed his pose, and it looked it it may have just been stuck colliding with the first pose, but it still collides pretty inaccurately.

It sounds like there’s a problem with the setup. I would expect the regular physics asset to work good enough for what you describe.

Could you post some screenshots so I can better understand this?

Maybe it is a problem with the setup. After more testing, we have run into some really strange results.

I have set SkeletalMeshComponent->bEnablePerPolyCollision = true. I created a quick test that does a trace against colliders and draws a red dot on the place of collision.

    FVector CamLoc;
	FRotator CamRot;

	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(CamLoc, CamRot); // Get the camera position and rotation
	const FVector StartTrace = CamLoc; // trace start is the camera location
	const FVector Direction = CamRot.Vector();
	const FVector EndTrace = StartTrace + Direction * 1000;

	// Perform trace to retrieve hit info
	FCollisionQueryParams TraceParams(FName(TEXT("MouseHover")), true, GetWorld()->GetFirstPlayerController());
	TraceParams.bReturnFaceIndex = true;
	TraceParams.bTraceComplex = true;
	TraceParams.bTraceAsyncScene = true;
	
	FHitResult hit(ForceInit);
	if (GetWorld()->LineTraceSingle(hit, StartTrace, EndTrace, ECC_MAX, TraceParams))
	{
		DrawDebugLine(GetWorld(), StartTrace, EndTrace, FColor::Blue, false);
	
		DrawDebugPoint(GetWorld(), hit.Location, 2, FColor::Red, true);
	}

If we leave the physics asset that was created on import alone with all of the primitive colliders, the primitive colliders collide as expected. If I delete the primitive colliders from the asset in the editor, but don’t save the changes, it will still collide against the primitive components, but also random triangles explode from the sides of the colliders. Then if I save the removal of the primitives from the physics asset, there is no longer any collision at all… So SkeletalMeshComponent->bEnablePerPolyCollision does nothing…

Are you setting bEnablePerPolyCollision to true in the editor or in code? The presence of the physics asset should have no affect when per poly collision is on so it sounds like a bug or something is going wrong. Would you be able to send me your asset so I could see if I can repro this (ori.cohen@epicgames.com)

Does it happen with simple skeletal mesh?

I sent an email a couple days ago. Have you had the chance to look at it yet?

Thanks for the help!

Sorry I’ve been swamped. I’m going to forward it to one of our support guys to make sure it gets more traction. Thanks for your patience

Hello, I’ve been using this per-poly collision system with skeletal meshes and it seems to work really well in editor, however with packaged builds (or running from DebugGame from visual studio) it doesn’t seem to do anything. I have verified that the boolean is still set to true and the collision mode is Block All Dynamic. Has anyone had a similar experience with this?

Hi,

I think there’s actually a bug about this internally already. I’ll try and get to it today

I’ve just submitted a fix for this. It should be in 4.6, but you can find it here on github:

https://github.com/EpicGames/UnrealEngine/commit/41d8bd904c13f2b257c2a093ae78b16c63781d20

Note that it ended up being a big change in code so you may want to wait for 4.6 unless it’s urgent to get the fix.

OHHH thank you thank you!! I thought I was going crazy, spent ages trying to find this!

#Dear Ori

Can you also look at this related issue, of not being able to have collision between per poly static meshes and the physics engine?

Thanks!

Rama