How do you shape trace without blueprints?

I need to check a box shaped area in front of my player for multiple objects.

I’m looking everywhere for documentation on shape tracing in C++ (or even just using shape components to check for overlap) and there doesn’t seem to be anything. No matter what I search, all I can find is information about line tracing or raycasting.

https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseRaycasts/Blueprints/#shapetraces
I found that you can include kismet libraries to use blueprint functions, but I haven’t found any way to look up how those functions would appear in C++.

I found these functions:

but they don’t include any examples and I don’t understand how the syntax works from these pages.

I’m at a loss and I would much rather keep my shape tracing in C++ than blueprints. I appreciate any help or direction, thanks.

edit:
this looks promising:

but I still don’t understand how the parameters work. I’ll keep trying in the meantime.

1 Like

Thank you! This is exactly what I needed.
Is there any way to draw this with a debug line or visualize it?

Yes. Take a look at the DrawDebugHelpers.h. There you can find all the debug visualizations you need.

Oh that’s great thank you so much!

This is very easy.

First of all you need have to create the shape you want to trace.
FCollisionShape Shape = FCollisionShape::MakeBox(FVector(50,50,50));

Then you have to declare your hit result.
FHitResult SweepResult;

To trace you just do the following:
GetWorld()->SweepSingleByChannel(SweepResult, StartLocation, EndLocation, ShapeRotation, ECC_Visible, Shape)

this returns true if the sweep hit something. If that is the case you can use the SweepResult object to get more information about what you hit. If you want to know about all hits use SweepMultiByChannel. That takes an array of FHitResult.

3 Likes