LineTraceForObjects Doesn't Show Line

Hello, attached I have 2 pictures. One is of the code where the LineTraceForObjects is, and the other is the collision settings of one of the actors I would like to pickup.

The problem is that, when I hit E (InputAction Pickup Item Pressed) I want to do a line trace searching for actors of type Pickups. However, in game, the line is never shown but the print string at the end does print if I have it just say hello so the LineTrace is being executed.

Since you’re using a First Person camera, could it be that you are simply looking directly down the line and need to move left/right to see it? If you’re lined up too perfectly with the linetrace you won’t be able to see it. You’ve probably already done this, but just making sure.

draw a debug point at hit location. Draw Debug Point | Unreal Engine Documentation

Pause sim and eject. pan around and verify the line trace isn’t hitting the pawn/capsule itself.

I have moved over and tried while spamming e but never saw the line. Also, if I were to use LineTraceByChannel the line would be there with the same Start and End code so hitting the pawn isnt right.

Take the line trace return value (bool), pipe it to a branch. Pipe the false to a print string (No Hit)

If you’re not getting hits, then look at your line trace length. Is it long enough to hit?
Check that your pickup does in fact have a collision and the collision is big enough.

​​​​​​​report back.

If Rev0verDrive’s suggestion doesn’t work, try drawing the line at a specific start location instead of the camera, also. Maybe there is some issue with your camera reference, and it’s actually drawing the line in a strange place.

I have done the false thing before and it would return false. However I have checked the collisions of my actors and they are fine. The length is fine as Ive also increased it to 500 with no change anyway. Its the fact that no line are being created in the first place but are with LineTraceByChannel.

If you’re getting a result, then the traces are in fact being executed.

Try …
On input: first person camera → is valid → branch - True → trace… False → print string (invalid cam).

So if getting a false is a result, how come there are no lines? Attached is what I believe is what you told me to do and it did return the Invalid Cam string. But what does that mean? Because the only reason that it can get to the string is by checking if the first person camera is valid at the start?

It means that I was most likely correct in my earlier post: the line is being drawn but it’s being drawn in a void location, so you can’t see it. It could be under the world, or way far away from you etc. The camera reference isn’t valid so it doesn’t know where to draw.

But that first reference is checking if the First Person Camera is valid and if it is then it does the linetrace then the Print String if the second branch condition it false.

I misunderstood. I see what you’re saying now. So, I think Rev meant that on the first branch in the image there, you would have the “false” hooked up to “invalid cam” print string, not the branch after the trace. If you’re getting something out of the “true” in that first branch, it means the camera ref is valid.

That makes more sense however the Error is not shown so that means that the camera is valid. So now what?

I went ahead and coded it out.

Create a new object type (PickupItem).
Created a BP parent class for pickup items. Static mesh, set collision object type to Pickup Item. Add a ItemName var (NAME)

Created a child BP for two items … G67 grenade and M26 HE Frag … set their meshes and item name vars.

Add an L key input for the trace logic to my character class.

Works exactly as it should.
If you are only seeing “No Hit” print string results then you absolutely need to make sure your camera is legit and your pickup items collision object type is “pickup item” (or equivalent).

No trace lines on screen points to the camera isn’t legit. Off hand the only other thing I can think of is the cameras world position is not nearby. To debug that you’d print string the cameras world position and compare it against the characters skeletal mesh (head socket) position. They won’t match up 1:1, but they should be close given you socket the cam near the head. You could also draw a huge debug point at the cameras world location.

Thanks for putting in the work for that video however I still get no hit which means the camera is valid. I did a DrawDebugLine using the same start and end points for the LineTraceForObjects and could see the line so I don’t think its the camera. In the project settings I have the object channel Pickups response to be block, is that correct? Also, All the collision responses and object responses are set to block in the actors collision settings for the actor I want to pickup.

Object Channel: Pickups/Block … I have mine to ignore by default. This has no bearing on your issue, but it’s better to have it ignored by default. This will keep you from having to adjust collision settings for all other actors in the future. Time saver.

e.g. check your characters collision. Pickups blocks the pawn and capsule. Gameplay wise you wouldn’t want this.

The only thing that really matters for the trace to hit is that your items object type is set to Pickups. What it ignores/blocks etc doesn’t matter. The trace is only going to “HIT” object types of Pickups.
e.g. the trace will go through (ignore) all other object types. Unless you add other object types to the array.

Here’s another vid highlighting some of this stuff.

This was very annoying but I did get it fixed. Alls I had to do was restart the editor ;( I have no idea why this problem arose but after doing the restart of the editor it fixed the issue. But thanks to both of you for the help.