Download

Intersection of mesh and a line

Hi. I’m failing to find what seems to be a pretty basic thing, hoping someone can direct me.
I have instanced static meshes in my level and I would like for a specific instance to find a “hit point” - a closest (or all) intersection of this mesh with a straight line.
I’m working in C++ but if there is a solution with Blueprints that would help too.
Thanks!

There are different types of line traces available. Here’s an overview:

1 Like

Thank you!
Yes, I’ve been looking through those, but they seem to focus on finding an object that’s being hit, not checking for a hit against a specific mesh. In my level I may have hundreds or thousands of meshes, but I only need to test for intersection against one of them - the floor. And I need to do this as fast as possible. Wouldn’t these methods be excessive for my case where I already know which object is being hit?

I’m guessing I’m supposed to use TraceLineByChannel and create my own custom “Floor” channel, right? Would this completely exclude all other objects from being tested? If so, I guess that’s exactly what I need!

There is ActorLineTraceSingle() and LineTraceComponent()

They also have Blueprint equivalents – I seem to recall a “line trace against this array of actors” node, but I forget the exact name.

Right-click, type “Trace” and see what pops up in the menu!

1 Like

Nice, this looks exactly like what I was looking for.

It however doesn’t work exactly like I expected. I have a method where I instantiate the floor and then run a loop to instantiate static objects that I want to sit on the floor (all of these are instantiated meshes).
So I’m trying to run a trace line from each object vertically to find the intersection with the floor, and then place the object there. This logic works, but apparently meshes instanced inside this same method are not “visible” to the trace. It does work on those that have already been placed in the scene before this method was called. So is the AddInstance() method asynchronous and I need to skip a tick for the mesh to actually appear in the world and become “hittable”?

Oof, nevermind my last comment. Turns out I was setting self to be ignored, but the instanced meshes belong to the same actor that does the tracing. Passing null for the list of ignores did the trick.

Thanks a lot @jwatte and @Speido!