Strange issue with traces

I’m trying to get all Actors that are overlapping a box. For this purpose I created this function:

	template <typename T>
	static void GetActorsInArea(const UObject* WorldContextObject, TArray<T*>& OutActors, const FVector& BoxCenterLocation, float BoxExtent = 0)
	{
		if (UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull))
		{
			UE_LOG(LogTemp, Warning, TEXT("START"))
			TArray<FHitResult> HitResults;
			FVector StartLocation = BoxCenterLocation + FVector(0, 0, 100);
			FVector EndLocation = BoxCenterLocation - FVector(0, 0, 100);

			FCollisionShape CollisionShape;
			CollisionShape.SetBox(FVector(BoxExtent));
			
			FCollisionQueryParams QueryParams;
			QueryParams.bIgnoreBlocks = true;

			World->SweepMultiByChannel(HitResults, StartLocation, EndLocation, FQuat(), ECC_WorldDynamic, CollisionShape, QueryParams);
			//World->SweepMultiByObjectType(HitResults, StartLocation, EndLocation, FQuat(), FCollisionObjectQueryParams(0), CollisionShape, QueryParams);

			for (FHitResult& HitResult : HitResults)
			{
				if (T* ValidActor = Cast<T>(HitResult.GetActor()))
				{
					UE_LOG(LogTemp,Warning,TEXT("ADD"))
					OutActors.Add(ValidActor);
					DrawDebugBox(World, BoxCenterLocation, FVector(BoxExtent + 10), FColor::Blue, false, 100);
				}
			}
			DrawDebugBox(World, BoxCenterLocation, FVector(BoxExtent + 5), FColor::Red, false, 100);
			UE_LOG(LogTemp, Warning, TEXT("END"))
		}
	}

The function is called for each location that is represented by a green debug sphere. The problem is that the tiles are detected in every second function call (in other cases nothing is detected). I do not know where I make the mistake, so I am asking you for help. (The cubes and floor have disabled collisions)

254218-2.png

Hey !
i guess thoses boxes are all the sames but you could double check they are actually world dynamics types ? ( procedural generation with different bp ? ) ( check at runtime to be extra sure )
alos what does the debugger say ? ( put a breakpoint in there and check what happening )

Does it has some hit result but no actor associated ? does it has no hit result ?
also, what BoxExtent value are you passing in there ?

All the tiles have the OverlapAllDynamic preset. I’ve checked the object types and channels and everything is set correctly.

This is weird because the only difference is the amount of hit objects…
Here are two screenshots of the local variables inside the GeomSweepMulti_PhysX() function

Success:

Fail:

BoxExtent = 25. It is the same size as the white cube.

I do not know if it can affect the output but there is one more difference inside the SweepMultiByChannel function - more precisely about the Rot variable.

Screenshot:

strange thing…
try with
FCollisionQueryParams QueryParams;
QueryParams.bIgnoreBlocks = false;
just to check.
also could you try the method
OverlapMultiByChannel
because it fits more what you are trying to achieve so if it work its good

With QueryParams.bIgnoreBlocks = false the trace could be blocked and not even reach the tiles. But I think I found my mistake.

Instead of writing:

CollisionShape.SetBox(FVector(BoxExtent));

It should be:

CollisionShape.MakeBox(FVector(BoxExtent));

And indeed the OverlapMultiByChannel method fits much more, this is what I was looking for!
Thank you very much for your help :slight_smile: