Exception on first invocation of SweepMultiByProfile

I’m using SweepMultiByProfile in a UBTService and I always get an exception the very first time it is executed when playing the game. I use similar sweeps in other classes without an issue.

void UAI_PickupScanner::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
	UBlackboardComponent* blackBoardComp = OwnerComp.GetBlackboardComponent();
	TArray<FHitResult> hits;
	APawn* pawn = OwnerComp.GetAIOwner()->GetPawn();
	FVector actorLocation = pawn->GetActorLocation();

	GetWorld()->SweepMultiByProfile(hits, actorLocation, actorLocation, FQuat::Identity, FName("OverlapAllDynamic"), FCollisionShape::MakeSphere(SearchRadius));

  ........

SearchRadius is normally set to 4000.0f

This causes the game to hang for about 4 seconds, with StackWalkAndDump taking 3.5 seconds on average. It only happens the first time the TickNode and the sweep are called, and subsequently the game runs without an issue.

Here is the relevant part of the exception:

LogStats: FPlatformStackWalk::StackWalkAndDump - 3.634 s
LogOutputDevice: Error: === Handled ensure: ===
LogOutputDevice: Error: Ensure condition failed: OutResult.ImpactNormal.IsNormalized() [File:D:\Build++UE4+Release-4.18+Compile\Sync\Engine\Source\Runtime\Engine\Private\Collision\CollisionConversions.cpp] [Line: 992]
LogOutputDevice: Error: Stack:
LogOutputDevice: Error: [Callstack] 0x00000000E2902786 UE4Editor-Core.dll!FWindowsPlatformStackWalk::StackWalkAndDump() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\core\private\windows\windowsplatformstackwalk.cpp:200]
LogOutputDevice: Error: [Callstack] 0x00000000E26A123A UE4Editor-Core.dll!FDebug::EnsureFailed() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:298]
LogOutputDevice: Error: [Callstack] 0x00000000E26BB906 UE4Editor-Core.dll!FDebug::OptionallyLogFormattedEnsureMessageReturningFalse() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:425]
LogOutputDevice: Error: [Callstack] 0x00000000D62883E5 UE4Editor-Engine.dll!ConvertOverlappedShapeToImpactHit() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\collision\collisionconversions.cpp:992]
LogOutputDevice: Error: [Callstack] 0x00000000D6288951 UE4Editor-Engine.dll!ConvertQueryImpactHit() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\collision\collisionconversions.cpp:437]
LogOutputDevice: Error: [Callstack] 0x00000000D627AD18 UE4Editor-Engine.dll!AddSweepResults() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\collision\collisionconversions.cpp:595]
LogOutputDevice: Error: [Callstack] 0x00000000D62974CC UE4Editor-Engine.dll!GeomSweepMulti_PhysX() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\collision\physxcollision.cpp:1201]
LogOutputDevice: Error: [Callstack] 0x00000000D6296B5D UE4Editor-Engine.dll!GeomSweepMulti() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\collision\physxcollision.cpp:1254]
LogOutputDevice: Error: [Callstack] 0x00000000D62BD8AE UE4Editor-Engine.dll!UWorld::SweepMultiByChannel() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\collision\worldcollision.cpp:147]
LogOutputDevice: Error: [Callstack] 0x00000000D62BDBE3 UE4Editor-Engine.dll!UWorld::SweepMultiByProfile() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\collision\worldcollision.cpp:356]
LogOutputDevice: Error: [Callstack] 0x00000000CA01F42B UE4Editor-Horu-9517.dll!UAI_BodypartScanner::TickNode() [c:\work\horu\horu\source\horu\private\ai\ai_pickupscanner.cpp:18]
LogOutputDevice: Error: [Callstack] 0x00000000DE3263BA UE4Editor-AIModule.dll!UBTAuxiliaryNode::WrappedTickNode() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\aimodule\private\behaviortree\btauxiliarynode.cpp:66]

I have the same issue in 4.17.

It only happens once in Editor and never again until I restart it.

I’m working with Blueprint only.

EDIT: I thought it was because the first swept was returning 0 result but it’s freezing also with 1+ results.

EDIT2: I’m trying to find a workaround (I need to restart my project each time :p).

EDIT3. I arrived at a point where I does not freezes / stack walk and dump when triggering the first MultiSphereTrace by isolating the function and removing any custom parameters used. I’ll update with more information.

EDIT4: More info:
I’m using variables for TraceChannel, TraceComplex, ActorsToIgnore, DrawDebugType, IgnoreSelf and DrawTime. I played around plugging / unplugging these variables into the MultiSphereTraceByChannel node. I did not arrive to a conclusion yet but I have a feeling it comes from the “IgnoreSelf” boolean.

230981-example.jpg

EDIT5. I reset every parameter to my initial setup except for IgnoreSelf and TraceComplex and I still don’t experience the first freeze. Trying right now with IgnoreSelf unchecked (which is the setup I want). Ok, it did freeze with the “IgnoreSelf” parameter left unchecked. I’m performing that function on an ActorComponent and the starting location of the sphere is the exact location of the actor owning the actor component. Going to think a bit further about this.

The problem comes from the “IgnoreSelf” parameter if you’re using the Blueprint alternative of MultiSphereTraceByChannel.

When using this node for the first time of an editor launch, with the parameter “IgnoreSelf” unchecked, it freezes for 4 seconds and generates a StackWalkAndDump.

I did not find a workaround to the problem but I isolated it.

I’m not excluding any actors in my call to SweepMultiByProfile, and the c++ version doesn’t really have an “ignore self” parameter either. All it has is FCollisionQueryParams where I could (but don’t, in this case) specify any actors to ignore.

Yup but I strongly suspect both cases to be related somehow. Maybe the code inside the “MultiSphereTraceByChannel” node can help us out resolve our error.

Turns out not to be a bug: my 2nd and 3rd parameters were the same, making the IsNormalized() check fail. Not sure why it didn’t keep failing after the first invocation, though.

1 Like

Adding 0.01 to any axis off the initial sweep position might get rid of the problem.

This actually fixed it for me on 4.20.3. The accepted answer is merely an acknowledgement of the symptoms but adding a very small amount to the X-axis kept the engine from locking up. This should be the accepted answer @GlassBeaver.