# "Find Collision UV" always returns zero for Skeletal Meshes

**URL:** <https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548>\
**Category:** Rendering\
**Tags:** Trace, uv, unreal-engine, collision-responses, skeletalmesh, question, Blueprint\
**Created:** [December 6, 2016, 11:46pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548 "2016-12-06T23:46:50Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![dokipen](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dokipen/32/1145419_2.png) [@dokipen](https://forums.unrealengine.com/u/dokipen)\
**Post date:** [April 26, 2019, 4:28am UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/21 "2019-04-26T04:28:27Z")

</div>

Would be great if this could be integrated into the engine.

---

<div class="post-metadata">

**Author:** ![Bob3DGames](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bob3DGames](https://forums.unrealengine.com/u/Bob3DGames)\
**Post date:** [June 15, 2019, 8:45pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/22 "2019-06-15T20:45:14Z")

</div>

Thanks, Guitarana. However, I’m pretty new to the C++ side of things and I’m not altogether sure where to put that code. Are you able to help please?

---

<div class="post-metadata">

**Author:** ![UnexpectedSquirt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnexpectedSquirt](https://forums.unrealengine.com/u/UnexpectedSquirt)\
**Post date:** [June 15, 2019, 9:22pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/23 "2019-06-15T21:22:53Z")

</div>

It’s a static function, so you’d want to put it in a static library of your own. Something along the lines of this (derive from UObject)

```
 #pragma once
 
 // Epic includes
 #include "CoreMinimal.h"
 #include "UObject/NoExportTypes.h"
 
 // YourGame Includes
 #include "YourStaticLibrary.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class YOURGAME_API UYourGameStaticLibrary : public UObject
 {
     GENERATED_BODY()

public:

UFUNCTION(BlueprintCallable,Category=HitDetection)
static void FindCollisionUVOnSkeletalMesh(const struct FHitResult& Hit, FVector2D& UV);

};
```

---

<div class="post-metadata">

**Author:** ![Bob3DGames](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bob3DGames](https://forums.unrealengine.com/u/Bob3DGames)\
**Post date:** [June 16, 2019, 8:19am UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/24 "2019-06-16T08:19:59Z")

</div>

Ah, that was just the little nudge I needed. I have it working now. Thanks!

---

<div class="post-metadata">

**Author:** ![UnexpectedSquirt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnexpectedSquirt](https://forums.unrealengine.com/u/UnexpectedSquirt)\
**Post date:** [July 11, 2019, 3:00pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/25 "2019-07-11T15:00:25Z")

</div>

One thing that’s worth mentioning is that this code won’t work in shipping builds. You will need to wrap it in editor-only defines

---

<div class="post-metadata">

**Author:** ![UnexpectedSquirt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnexpectedSquirt](https://forums.unrealengine.com/u/UnexpectedSquirt)\
**Post date:** [July 11, 2019, 7:00pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/26 "2019-07-11T19:00:11Z")

</div>

It’s not shippable code, so they wont do that.

---

<div class="post-metadata">

**Author:** ![UnexpectedSquirt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnexpectedSquirt](https://forums.unrealengine.com/u/UnexpectedSquirt)\
**Post date:** [July 31, 2019, 7:05pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/27 "2019-07-31T19:05:47Z")

</div>

Hey guys,

I made a version of Guitaran’s function that should be useable in non-editor builds. It can be considered a full replacement for Epic’s FindCollisionUV() as it will work for both skeletal and static meshes.

Enjoy!

> **[FindCollision UV - Pastebin.com](https://pastebin.com/wr6PHta3)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![AlxDe111](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlxDe111](https://forums.unrealengine.com/u/AlxDe111)\
**Post date:** [December 22, 2020, 5:09am UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/28 "2020-12-22T05:09:59Z")

</div>

You are amazing! Thank you!

---

<div class="post-metadata">

**Author:** ![BarrierAbyss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BarrierAbyss](https://forums.unrealengine.com/u/BarrierAbyss)\
**Post date:** [June 13, 2021, 4:23am UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/29 "2021-06-13T04:23:58Z")

</div>

Very powerful, but still lacking something, the pickup points of the skeletal mesh need to be converted to the local space of the initial pose:

```cpp
UFUNCTION(BlueprintCallable, BlueprintPure)
static FTransform GetSkeletalMeshRefPose(USkeletalMesh* SkeletalMesh,int BoneIndex)
{
	FTransform MeshBonePoseTransform;
	MeshBonePoseTransform.SetIdentity();
	MeshBonePoseTransform = SkeletalMesh->RefSkeleton.GetRefBonePose()[BoneIndex];
	int ParentBoneIndex = SkeletalMesh->RefSkeleton.GetParentIndex(BoneIndex);
	if (ParentBoneIndex == INDEX_NONE)
	{
		return MeshBonePoseTransform;
	}
	else
	{
		return MeshBonePoseTransform * GetSkeletalMeshRefPose(SkeletalMesh, ParentBoneIndex);
	}
}

```

```cpp
UFUNCTION(BlueprintCallable,BlueprintPure)
static bool GetHitResultPointInRefPose(const struct FHitResult& HitResult, FVector &Point)
{
	if (UPrimitiveComponent* HitPrimComp = HitResult.Component.Get())
	{
		FVector HitPoint = HitResult.ImpactPoint;
		if (USkeletalMeshComponent* SkelComp = Cast<USkeletalMeshComponent>(HitPrimComp))
		{
			int BoneIndex = SkelComp->SkeletalMesh->RefSkeleton.FindBoneIndex(HitResult.BoneName);
			//FTransform PoseTransform = SkelComp->SkeletalMesh->RefSkeleton.GetRefBonePose()[BoneIndex];
			HitPoint = SkelComp->GetSocketTransform(HitResult.BoneName).InverseTransformPosition(HitPoint);
			Point= GetSkeletalMeshRefPose(SkelComp->SkeletalMesh, BoneIndex).TransformPosition(HitPoint);
			return true;
		}
	}
	return false;
}

```

I’ve reformatted the text of this post.

---

<div class="post-metadata">

**Author:** ![BarrierAbyss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BarrierAbyss](https://forums.unrealengine.com/u/BarrierAbyss)\
**Post date:** [June 14, 2021, 2:17pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/30 "2021-06-14T14:17:51Z")

</div>

Thank you for providing the method to read skeletal mesh renderdata.I have solved it.

1. For skelemesh need convert impact  
point and impact normal from world  
space to **ref pose’s local space**.
2. Then, create line segment by  
converted impact point and converted  
impact normal.
3. Then, use the line segment to get  
Intersection with triangle in  
skeletal mesh. PS:the target  
triangle can get intersection
4. At Last,use the intersection to get  
UV from the target triangle. It is  
workable but the efficiency may need  
to be optimized.

also:

1. For skelemesh need convert impact  
point and impact normal from world  
space to **ref pose’s local space**.

2. Then, create line segment by  
converted impact point and converted  
impact normal.

3. Use the line segment linetrace  
staticmesh which is build from  
skeletal mesh,but by this way the  
line segment need convert to  
component space.

4. Find UV from the hitresult.

 ![341451-uvpick.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/1/0/610cf5e415ccb5dc642d0f59c02cc5b7fa986a7e.png)

---

<div class="post-metadata">

**Author:** ![Wakalacaqa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wakalacaqa](https://forums.unrealengine.com/u/Wakalacaqa)\
**Post date:** [July 17, 2021, 12:12am UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/31 "2021-07-17T00:12:48Z")

</div>

can you post the code? lol i dont understand nothing im just copy and paste things and im stuck here

---

<div class="post-metadata">

**Author:** ![Wakalacaqa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wakalacaqa](https://forums.unrealengine.com/u/Wakalacaqa)\
**Post date:** [July 19, 2021, 6:10am UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/32 "2021-07-19T06:10:23Z")

</div>

can you post the code? lol i dont understand nothing im just copy and paste things and im stuck here

---

<div class="post-metadata">

**Author:** ![Bob3DGames](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bob3DGames](https://forums.unrealengine.com/u/Bob3DGames)\
**Post date:** [July 19, 2021, 9:48am UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/33 "2021-07-19T09:48:23Z")

</div>

You should delete this as it isn’t an answer and you could be down-voted.

---

<div class="post-metadata">

**Author:** ![BarrierAbyss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BarrierAbyss](https://forums.unrealengine.com/u/BarrierAbyss)\
**Post date:** [September 14, 2021, 5:18pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/34 "2021-09-14T17:18:26Z")

</div>

- A few months have passed…
- Their answer solved for me the problem of how to read the triangles from skelemesh.The spatial arrangement of these triangles is the initial pose.
- So if you want to pick up more correct triangles at runtimer,You must first understand the principle of skeletal animation.you need to convert the collision point and its direction into the coordinate system of the initial pose at first.
- But the serious impact of collision fit on the results.For better results, unless Epic provides a better way to create skeletal collision bodies: for example, generate them based on user-selected vertices.
- My code relies on an extension plugin that I wrote, so I can only provide algorithms and ideas.

---

<div class="post-metadata">

**Author:** ![BarrierAbyss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BarrierAbyss](https://forums.unrealengine.com/u/BarrierAbyss)\
**Post date:** [September 14, 2021, 5:46pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/35 "2021-09-14T17:46:52Z")

</div>

Roughly as follows:

- From the HitResult, you can get the impact point and impact normal.They are in the world space.You also can read the bone name from the HitResult.
- Get the bone’s world transform(It is actually the transformation matrix) form the skelemesh by bone’s name.get the Inverse of this transform.
- Convert impact point and impact normal by the Inverse of transform,now the point and normal into the bone space.

---

<div class="post-metadata">

**Author:** ![BarrierAbyss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BarrierAbyss](https://forums.unrealengine.com/u/BarrierAbyss)\
**Post date:** [September 14, 2021, 5:51pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/36 "2021-09-14T17:51:10Z")

</div>

```cpp
UFUNCTION(BlueprintCallable, BlueprintPure)
static FTransform GetSkeletalMeshRefPose(USkeletalMesh* SkeletalMesh,int BoneIndex)
{
	FTransform MeshBonePoseTransform;
	MeshBonePoseTransform.SetIdentity();
	MeshBonePoseTransform = SkeletalMesh->RefSkeleton.GetRefBonePose()[BoneIndex];
	int ParentBoneIndex = SkeletalMesh->RefSkeleton.GetParentIndex(BoneIndex);
	if (ParentBoneIndex == INDEX_NONE)
	{
		return MeshBonePoseTransform;
	}
	else
	{
		return MeshBonePoseTransform * GetSkeletalMeshRefPose(SkeletalMesh, ParentBoneIndex);
	}
}

```

```cpp
UFUNCTION(BlueprintCallable,BlueprintPure)
static bool GetHitResultPointInRefPose(const struct FHitResult& HitResult, FVector &Point)
{
	if (UPrimitiveComponent* HitPrimComp = HitResult.Component.Get())
	{
		FVector HitPoint = HitResult.ImpactPoint;
		if (USkeletalMeshComponent* SkelComp = Cast<USkeletalMeshComponent>(HitPrimComp))
		{
			int BoneIndex = SkelComp->SkeletalMesh->RefSkeleton.FindBoneIndex(HitResult.BoneName);
			//FTransform PoseTransform = SkelComp->SkeletalMesh->RefSkeleton.GetRefBonePose()[BoneIndex];
			HitPoint = SkelComp->GetSocketTransform(HitResult.BoneName).InverseTransformPosition(HitPoint);
			Point= GetSkeletalMeshRefPose(SkelComp->SkeletalMesh, BoneIndex).TransformPosition(HitPoint);
			return true;
		}
	}
	return false;
}

```

I’ve reformatted the text of this post.

---

<div class="post-metadata">

**Author:** ![BarrierAbyss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BarrierAbyss](https://forums.unrealengine.com/u/BarrierAbyss)\
**Post date:** [September 14, 2021, 6:02pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/37 "2021-09-14T18:02:43Z")

</div>

- You can find the bone index by bone name.
- and use the function I pasted.you can get the bone’s transform of Initial pose/ref pose.
- Convert the point and normal which is in the bone space by this transform.
- Use the point and normal which is now in the initial pose space to pick the triangles.

---

<div class="post-metadata">

**Author:** ![BarrierAbyss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BarrierAbyss](https://forums.unrealengine.com/u/BarrierAbyss)\
**Post date:** [September 14, 2021, 6:08pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/38 "2021-09-14T18:08:52Z")

</div>

PS:It is not a good idea to traverse all triangles, especially if the number of faces is particularly high, all it takes is to build data structures to optimize them, but that is another matter.

---

<div class="post-metadata">

**Author:** ![BarrierAbyss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BarrierAbyss](https://forums.unrealengine.com/u/BarrierAbyss)\
**Post date:** [March 9, 2022, 1:40pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/41 "2022-03-09T13:40:45Z")

</div>

When you get the coordinates and directions of the collision points in RefPose space, you can easily draw up a start point and an end point and replace them directly into the functions given by @Guitarana .

---

<div class="post-metadata">

**Author:** ![yurik444](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@yurik444](https://forums.unrealengine.com/u/yurik444)\
**Post date:** [June 22, 2022, 3:11pm UTC](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548/42 "2022-06-22T15:11:03Z")

</div>

I had to edit the original code to be able to choose the UV index

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/f/7df752da3fb3a85345af0276429c49d4bc4edb0c.png)

[Previous page](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548.md?page=1)

[Next page](https://forums.unrealengine.com/t/find-collision-uv-always-returns-zero-for-skeletal-meshes/378548.md?page=3)
