UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ScopedSQHitchRepeater.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
9#include "PhysXPublic.h"
12#include "WorldCollision.h"
13
14#if DETECT_SQ_HITCHES
16{
17 static int SQHitchDetection;
19
22
23 static float SQHitchDetectionThreshold;
25};
26#endif
27
30{
31#if DETECT_SQ_HITCHES
32 FVector Start;
34 FTransform Pose;
35 ECollisionChannel TraceChannel;
36 const FCollisionQueryParams& Params;
37 bool bInTM;
38
40 : Start(InStart)
41 , End(InEnd)
42 , TraceChannel(InTraceChannel)
43 , Params(InParams)
44 , bInTM(false)
45 {
46 }
47
49 : Pose(InPose)
50 , TraceChannel(InTraceChannel)
51 , Params(InParams)
52 , bInTM(true)
53 {
54 }
55
56 FString ToString() const
57 {
58 if (bInTM)
59 {
60 return FString::Printf(TEXT("Pose:%s TraceChannel:%d Params:%s"), *Pose.ToString(), (int32)TraceChannel, *Params.ToString());
61 }
62 else
63 {
64 return FString::Printf(TEXT("Start:%s End:%s TraceChannel:%d Params:%s"), *Start.ToString(), *End.ToString(), (int32)TraceChannel, *Params.ToString());
65 }
66 };
67#else
70 FString ToString() const { return FString(); }
71#endif // DETECT_SQ_HITCHES
72};
73
74template <typename BufferType>
76{
77#if DETECT_SQ_HITCHES
78 double HitchDuration;
81 BufferType& UserBuffer; //The buffer the user would normally use when no repeating happens
82 BufferType* OriginalBuffer; //The buffer as it was before the query, this is needed to maintain the same buffer properties for each loop
83 BufferType* RepeatBuffer; //Dummy buffer for loops
84 FCollisionQueryFilterCallback& QueryCallback;
86
87 bool RepeatOnHitch()
88 {
89 if (FSQHitchRepeaterCVars::SQHitchDetection)
90 {
91 if (LoopCounter == 0)
92 {
93 HitchTimer.Stop();
94 }
95
96 const bool bLoop = (LoopCounter < FSQHitchRepeaterCVars::SQHitchDetection) && (HitchDuration * 1000.0) >= FSQHitchRepeaterCVars::SQHitchDetectionThreshold;
98
99 QueryCallback.bRecordHitches = QueryCallback.bRecordHitches ? true : bLoop && FSQHitchRepeaterCVars::SQHitchDetection == 1;
100 if (bLoop)
101 {
102 if (!RepeatBuffer)
103 {
104 RepeatBuffer = new BufferType(*OriginalBuffer);
105 }
106 else
107 {
108 *RepeatBuffer = *OriginalBuffer; //make a copy to make sure we have the same behavior every iteration
109 }
110 }
111 return bLoop;
112 }
113 else
114 {
115 return false;
116 }
117 }
118
120 : HitchDuration(0.0)
122 , LoopCounter(0)
123 , UserBuffer(OutBuffer)
124 , OriginalBuffer(nullptr)
125 , RepeatBuffer(nullptr)
126 , QueryCallback(QueryCallback)
128 {
129 if (FSQHitchRepeaterCVars::SQHitchDetection)
130 {
131 OriginalBuffer = new BufferType(UserBuffer);
132 HitchTimer.Start();
133 }
134 }
135
136 BufferType& GetBuffer()
137 {
138 return LoopCounter == 0 ? UserBuffer : *RepeatBuffer;
139 }
140
142 {
143 if (QueryCallback.bRecordHitches)
144 {
145 const double DurationInMS = HitchDuration * 1000.0;
146 UE_LOG(LogCollision, Warning, TEXT("SceneQueryHitch: took %.3fms with %d calls to PreFilter"), DurationInMS, QueryCallback.PreFilterHitchInfo.Num());
147 UE_LOG(LogCollision, Warning, TEXT("\t%s"), *HitchDetectionInfo.ToString());
148 for (const FCollisionQueryFilterCallback::FPreFilterRecord& Record : QueryCallback.PreFilterHitchInfo)
149 {
150 UE_LOG(LogCollision, Warning, TEXT("\tPreFilter:%s, result=%d"), *Record.OwnerComponentReadableName, (int32)Record.Result);
151 }
152 QueryCallback.PreFilterHitchInfo.Empty();
153 }
154
155 QueryCallback.bRecordHitches = false;
156 delete RepeatBuffer;
157 delete OriginalBuffer;
158 }
159
160#else
165
166 BufferType& UserBuffer; //The buffer the user would normally use when no repeating happens
167
168 BufferType& GetBuffer() const { return UserBuffer; }
169 bool RepeatOnHitch() const { return false; }
170#endif
171};
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
ECollisionChannel
Definition EngineTypes.h:1088
return true
Definition ExternalRpcRegistry.cpp:601
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
Definition IConsoleManager.h:1580
Definition CollisionQueryFilterCallback.h:20
Definition ScopedTimers.h:32
CORE_API FString ToString() const
Definition UnrealNames.cpp:3537
Definition CollisionQueryParams.h:43
Definition ScopedSQHitchRepeater.h:30
FString ToString() const
Definition ScopedSQHitchRepeater.h:70
FHitchDetectionInfo(const FVector &, const FVector &, ECollisionChannel, const FCollisionQueryParams &)
Definition ScopedSQHitchRepeater.h:68
FHitchDetectionInfo(const FTransform &InPose, ECollisionChannel InTraceChannel, const FCollisionQueryParams &InParams)
Definition ScopedSQHitchRepeater.h:69
Definition ScopedSQHitchRepeater.h:76
BufferType & UserBuffer
Definition ScopedSQHitchRepeater.h:166
bool RepeatOnHitch() const
Definition ScopedSQHitchRepeater.h:169
FScopedSQHitchRepeater(BufferType &OutBuffer, FCollisionQueryFilterCallback &PQueryCallback, const FHitchDetectionInfo &InHitchDetectionInfo)
Definition ScopedSQHitchRepeater.h:161
BufferType & GetBuffer() const
Definition ScopedSQHitchRepeater.h:168