Line trace goes through mesh blueprint

When i click left mouse button I create a mesh at a certain location, but when I do line tracing, line trace just goes through mesh. I am using Add StaticMesh blueprint node to create the mesh. What can I do to fix this?

Are you running the line trace before or after you spawn your mesh?

If after: Double check your collision settings for the static mesh that you spawned.

Are you using the blueprint version of “Line Trace by Channel”? or the C++ version?
Does the collision settings match the line trace trace channel somehow?

If C++: You’re going to have to step into the line trace code on the engine side and loop through each object in the world and see where it’s failing. I’ve had to do this before, its tedious, but helped me figure out exactly where I was wrong.

If Blueprint: You are a bit limited here. You can draw the debug line or explode out the hit result and try to see what’s going on.

I am running it after I spawn. I mean, I run it on mouse click so I can spawn an object on the location where i clicked. Then I want to spawn an object on that spawned object, but they just get one into another…

34873-bp.png

Okay, look. I have a small level with just a small surface on which can character stand. Then I click on that surface to create a larger surface. Trace goes fine, hits the ground. But when I click on the surface I created, trace just doesn’t hit it, it goes through. Mu blueprint is made so object spawns on top of clicked object

So you mean that the object you are spawning is overlapping the object you clicked on, right?

If that’s the case, then your line trace is working correctly. It is giving you the impact point of your click position on the object, and then you’re spawning an object on that impact point. The problem you’re facing is that the impact point is the center of the object mesh you’re spawning, so you get object overlaps.

What you need to do is move the spawned object along the trace line until it is no longer intersecting with the point you clicked on. Sometimes this is easy, sometimes it’s really hard, but it really depends on the shape of the spawned object. If its a sphere, then you can just say that the impact point is a radius distance away from the center of the sphere and translate the center of the sphere by the radius amount along the line trace.

Or, you can do an uglier method which is a lot more simple: Spawn the object at the impact point, test for collision, if a collision is found, walk the object back by some fixed number of units, test for collision again, etc. and keep walking it back along the line until no collision was found with your impacting object (note that the hit result will also give you the object you hit). This method would handle the irregularly shaped objects, and is easier to implement, but is also more computationally expensive.

One last option is to just offset the mesh from its origin. If you’re spawning houses on terrain, then the origin of the house mesh could be centered on the floor of the house. When you spawn the house on the terrain position, the house mesh will automatically be offset to be right above the terrain hit position. Though, watch out: If your terrain is curved, then the corners of the house may by floating or sunken into the terrain. Take that into account for best visual results :slight_smile:

Everything is set up as you said, still not working. I will send you the level blueprint where everything happens. http://www.mediafire.com/download/qc1yjytfeno55tp/World.umap

Okay.

In the blueprint which you’re spawning, open up the details panel, find the Collision section, and verify that “Generate Overlap Events” is checked and under the “Collision Presets” section, under the “Trace Responses” section, the “visibility” checkbox is set to “block”. This is the default trace channel the line trace node uses and these should match.

1 Like

Thank you.

Alright, I’ll take a look at it tomorrow and get back to you.

Alright, I figured out what was happening. You don’t want to add mesh components to the scene. They don’t get added to the “World”. When you run a line trace, the line trace only traces through all objects in the world. The quick and easy fix is to put your mesh component inside of a blueprint, then use “Spawn Actor” on that blueprint.

You’ll notice that when you use “Spawn Mesh Component”, the meshes don’t get added to the “World Outliner” during game play (though, you can still collide with them in game.) I don’t know which object is getting those components :open_mouth:

When you use “Spawn Actor”, each mesh gets added to the world and your next line trace will intersect against it.

I think, the time you’d want to use “Spawn Mesh Component” is when you have a blueprint actor in mind already and you’d like to add to its list of meshes.

Does this help?