Line Traces / RayCasts How To Get UV Info From Hits

Overview Author: () In this wiki I provide you with the code to add the option to return UV information about raycast hits (PhysX) / Line Traces (UE4) ! This is an optional flag that you can set, t...

Updated over 4 years ago Edit Page Revisions

Overview

Author: ()

In this wiki I provide you with the code to add the option to return UV information about raycast hits (PhysX) / Line Traces (UE4) !

This is an optional flag that you can set, that does not affect performance or change UE4 behavior at all until it is turned on.

Even when turned on I have not noticed any performance impact, but if you examine my code you will see that performance of UE4 and the internal works of the PhysX code are entirely unchanged unless the optional flag is enabled.

File:PxUV.jpg

Github Engine Version

You must be using a Github version of UE4 in order to change these files below and recompile the engine.

Using a github version of UE4 you can add your own code to the engine and really make UE4 your own!

You can follow the steps here to obtain a github version of UE4!

How to get Github Version of UE4

My PhysX C++ Code For You!

I am using line numbers for the .cpp files especially to avoid posting any UE4 engine code publicaly.

Please note my line numbers are subject to change as more code is added to the engine.

The line numbers below are accurate to version 4.7.3 of UE4. So you can always download 4.7.3 source code from Github to ensure you are seeing the larger context of my cpp code changes.

The code you do see here are my additions to the UE4 engine code to support returning UV information from PhysX PxRaycastHits.

EngineTypes.h

Around line 1485, in FHitResult, add this

/** If CollisionQueryParams has bReturnUV set to true and the trace is a ray cast / line trace, then this value will be filled with the uv of the hit component at the point of impact */
UPROPERTY()
FVector2D UV;

CollisionQueryParams.h

Starting around line 38, make these two changes (emphasized with arrows)

/** Whether we want to return the UV at the hit location. Only valid for Line Traces / Ray casts */
bool bReturnUV;                         //