bSupportUVFromHitResults

bSupportUVFromHitResults

#Overview

name: bSupportUVFromHitResults

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 12 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of bSupportUVFromHitResults is to enable the storage and retrieval of UV information from collision hit results in Unreal Engine’s physics system. This setting is primarily used for enhancing the accuracy and functionality of physics-based interactions within the game environment.

This setting variable is relied upon by several Unreal Engine subsystems and modules, including:

  1. ProceduralMeshComponent
  2. Physics Engine (BodySetup, PhysicsSettings)
  3. ModelComponent
  4. GameplayStatics
  5. StaticMesh
  6. DynamicMeshComponent

The value of this variable is set in the PhysicsSettings class, which is part of the Engine’s configuration system. It can be modified through the project settings in the Unreal Editor.

This variable interacts with other physics-related variables and systems, particularly those involving collision detection and UV mapping. It’s often used in conjunction with other settings like bSupportFaceRemap and bSupportPhysicalMaterialMasks.

Developers must be aware of the following when using this variable:

  1. Enabling this feature increases memory usage and potentially impacts performance, as additional data needs to be stored and processed.
  2. It’s crucial for certain gameplay mechanics that require precise UV information from collision results, such as decal placement or texture-based effects at impact points.
  3. The setting is project-wide and requires a restart of the engine to take effect when changed.

Best practices when using this variable include:

  1. Only enable it if your project explicitly requires UV information from hit results, as it comes with a performance cost.
  2. When enabled, ensure that relevant meshes and materials are set up correctly to provide meaningful UV data.
  3. Use it in conjunction with the FindCollisionUV function in GameplayStatics for retrieving the UV information.
  4. Consider the impact on physics simulation performance, especially for projects with complex environments or many dynamic objects.
  5. Test thoroughly after enabling or disabling this feature, as it can affect various aspects of physics interactions and rendering.

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:328, section: [/Script/Engine.PhysicsSettings]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Runtime/ProceduralMeshComponent/Source/ProceduralMeshComponent/Private/ProceduralMeshComponent.cpp:957

Scope (from outer to inner):

file
function     bool UProceduralMeshComponent::GetPhysicsTriMeshData

Source code excerpt:


	// See if we should copy UVs
	bool bCopyUVs = UPhysicsSettings::Get()->bSupportUVFromHitResults; 
	if (bCopyUVs)
	{
		CollisionData->UVs.AddZeroed(1); // only one UV channel
	}

	// For each section..

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/PhysicsEngine/BodySetup.h:42

Scope: file

Source code excerpt:



/** UV information for BodySetup, only created if UPhysicsSettings::bSupportUVFromHitResults */
struct FBodySetupUVInfo
{
	/** Index buffer, required to go from face index to UVs */
	TArray<int32> IndexBuffer;
	/** Vertex positions, used to determine barycentric co-ords */
	TArray<FVector> VertPositions;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/PhysicsEngine/BodySetup.h:103

Scope: file

Source code excerpt:


	/** Whether to support UV from hit results */
	bool bSupportUVFromHitResults;

	/** Whether to support face remap, needed for physical material masks */
	bool bSupportFaceRemap;

	/** Error generating cook info for trimesh*/
	bool bTriMeshError;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/PhysicsEngine/PhysicsSettings.h:167

Scope (from outer to inner):

file
class        class UPhysicsSettings : public UPhysicsSettingsCore

Source code excerpt:

	/** If true, store extra information to allow FindCollisionUV to derive UV info from a line trace hit result, using the FindCollisionUV utility */
	UPROPERTY(config, EditAnywhere, Category = Optimization, meta = (DisplayName = "Support UV From Hit Results", ConfigRestartRequired = true))
	bool bSupportUVFromHitResults;

	/**
	* If true, physx will not update unreal with any bodies that have moved during the simulation. This should only be used if you have no physx simulation or you are manually updating the unreal data via polling physx.  */
	UPROPERTY(config, EditAnywhere, Category = Optimization)
	bool bDisableActiveActors;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/ModelComponent.cpp:652

Scope (from outer to inner):

file
function     bool UModelComponent::GetPhysicsTriMeshData

Source code excerpt:


	// See if we should copy UVs
	bool bCopyUVs = UPhysicsSettings::Get()->bSupportUVFromHitResults;
	if (bCopyUVs)
	{
		CollisionData->UVs.AddZeroed(1); // only one UV channel
	}

	const int32 NumVerts = Model->VertexBuffer.Vertices.Num();

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GameplayStatics.cpp:1447

Scope (from outer to inner):

file
function     bool UGameplayStatics::FindCollisionUV

Source code excerpt:

	bool bSuccess = false;

	if (!UPhysicsSettings::Get()->bSupportUVFromHitResults)
	{
		FMessageLog("PIE").Warning(LOCTEXT("CollisionUVNoSupport", "Calling FindCollisionUV but 'Support UV From Hit Results' is not enabled in project settings. This is required for finding UV for collision results."));
	}
	else
	{
		UPrimitiveComponent* HitPrimComp = Hit.Component.Get();

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/BodySetup.cpp:57

Scope (from outer to inner):

file
function     FCookBodySetupInfo::FCookBodySetupInfo

Source code excerpt:

	bConvexDeformableMesh(false),
	bCookTriMesh(false),
	bSupportUVFromHitResults(false),
	bSupportFaceRemap(false),
	bTriMeshError(false)
{
}

UBodySetup::UBodySetup(FVTableHelper& Helper)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/BodySetup.cpp:329

Scope (from outer to inner):

file
function     void UBodySetup::GetCookInfo

Source code excerpt:

	}

	OutCookInfo.bSupportUVFromHitResults = UPhysicsSettings::Get()->bSupportUVFromHitResults || bSupportUVsAndFaceRemap;


}

void FBodySetupUVInfo::FillFromTriMesh(const FTriMeshCollisionData& TriangleMeshDesc)
{

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/BodySetup.cpp:1444

Scope (from outer to inner):

file
function     void UBodySetup::GetGeometryDDCKey

Source code excerpt:

		(int32)bGenerateNonMirroredCollision,
		(int32)bGenerateMirroredCollision,
		(int32)UPhysicsSettings::Get()->bSupportUVFromHitResults,
		(int32)GetCollisionTraceFlag(),
		UPhysicsSettings::Get()->SolverOptions.CollisionMarginFraction,
		UPhysicsSettings::Get()->SolverOptions.CollisionMarginMax,
		(int32)BODY_SETUP_GEOMETRY_KEY_VER);

	if (bSupportUVsAndFaceRemap)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/Experimental/ChaosCooking.cpp:356

Scope (from outer to inner):

file
namespace    Chaos
function     void FCookHelper::Cook

Source code excerpt:

		Cooking::BuildTriangleMeshes(ComplexImplicits, FaceRemap, VertexRemap, CookInfo);

		if(CookInfo.bSupportUVFromHitResults)
		{
			UVInfo.FillFromTriMesh(CookInfo.TriangleMeshDesc);
		}

		if(!CookInfo.bSupportFaceRemap)
		{

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:7476

Scope: file

Source code excerpt:

	TMap<int32, int32> MeshToCollisionVertMap; // map of static mesh verts to collision verts

	bool bCopyUVs = bSupportPhysicalMaterialMasks || UPhysicsSettings::Get()->bSupportUVFromHitResults; // See if we should copy UVs

	// If copying UVs, allocate array for storing them
	if (bCopyUVs)
	{
		CollisionData->UVs.AddZeroed(LOD.GetNumTexCoords());
	}

#Loc: <Workspace>/Engine/Source/Runtime/GeometryFramework/Private/Components/DynamicMeshComponent.cpp:1248

Scope (from outer to inner):

file
function     bool UDynamicMeshComponent::GetPhysicsTriMeshData

Source code excerpt:

bool UDynamicMeshComponent::GetPhysicsTriMeshData(struct FTriMeshCollisionData* CollisionData, bool InUseAllTriData)
{
	// todo: support UPhysicsSettings::Get()->bSupportUVFromHitResults

	// this is something we currently assume, if you hit this ensure, we made a mistake
	ensure(bEnableComplexCollision);

	ProcessMesh([&](const FDynamicMesh3& Mesh)
	{