Where would I start to build a get UV coordinate from raycast method?

There doesn’t appear to be any functionality for retrieving the UV coordinates from a raycast. This is pretty common functionality in Unity and I would like to bring it into UE4. Where would I find the implementation file for the object that holds the UVs of a mesh? I would like to extend the raytrace functionality to retrieve this information.

Thanks!

This appears to have some basic functionality for retrieving the color from uv coordinates. https://docs.unrealengine.com/latest/INT/API/Editor/MeshPaint/FImportVertexTextureHelper/PickVertexColorFromTex/index.html

I suppose now I need to find where or how I can convert the raycast hit location into UV coordinates.

Is the FHitResult the main return type for traces? FHitResult | Unreal Engine Documentation

I see that is can return the face index. Does anyone know how I could use the face index to reference the UV associated with this face? I presume if I can get that then I would need to create an offset from the world space hit location , distance between the vertices of this face - converted to UV space.

Have you been able to solve this one?

The Hit returns a triangle index but I haven’t been able to relate that with the mesh’s indice or vertex buffer. The hit result does not return actual UV coords so this might be needed for this functionality…Do you know how to relate those two?

As it turns out there isn’t any support for this right away in UE4. I found other posts looking for similar stuff but it’s not included in the engine. You have to assemble something through code. I decided to design around it. Sorry and Good luck!

I found this post for unity written in javascript, but it’s mathematical not using their raycast stuff.

If you take your collision point and/or raycast point you might be able to make something of this. You’ll need to get your triangle points and intersection/collision point into the same space (local or world) first, but then the math should work as posted above.

I need to do this in UE4 with a generated mesh. If I succeed I’ll come back here and post a solution. If you don’t hear back from me in a month or more send a search party, I’m probably curled up under my desk scared and hungry.

I realize this is an old question but I recently struggled with this as well and I figured I would post it here to help anyone else that may need this. I posted the code I used over here.

As of 4.13, a Find Collision UV node was finally added.

Ref: Unreal 4.13 Notes, see “NEW: TEXTURE COORDINATES FROM LINE TRACES”

You can use a Line Trace hit result to find the UV that was hit. But make sure to do the following:

  1. Under Project Settings > Engine > Physics > Optimization, enable “Support UV From Hit Results”. This enables the feature but uses more CPU to store the UV information.
  2. When performing the Line Trace, ensure, “Trace Complex” is checked.