How to use line trace from character blueprint in an actor blueprint

Hello,

I am new to Unreal and I have trouble using line trace. Here’s the deal:

I’ve created a simple line trace in a custom Character Blueprint. It works as in it “does the thing with the line shooting out of my camera”. (see the picture for the blueprint). I’ve checked if it returns component/actor values correctly, and so far it does.

Then, I have a lift blueprint and this bp contains several buttons. To cut it short, I would like to activate those buttons with “OnActionIEvent” but only when the player looks at it.

The problem is, I have no idea how to “call” the line trace (or its Hit Results) from my Character BP in my Lift BP. I’ve read about things but I’m struggling all the same. I’ve seen people talk about functions but I’m not sure how that works in this case.

Can anyone help me with this?
Thanks for your attention and have a good day!

Ledifen

1 Like

Drag a wire from Hit Actor and cast it to Lift BP. This will give you access to the object hit with the trace, all its variables, events and functions (if the lift has any).

Do note that Tick executes every frame, perhaps this should be happening when the player presses a button instead?

Thank you for the quick answer.
Oh my! That was so simple. Actually, I was heavily confused by the fact that I could not find the Cast To LiftBP when I dragged a link from hit component (I wanted component because when I tested it (with print screen), hit component would return the names off the different components (duh!) of the blueprint, and hit actor would only return “Lift BP”.

Whatever! Sometimes the answer is just that easy :).

Yes I do know that Tick is every frame, I tend to avoid it as much as possible but as I want the button to highlight when the player looks at it, I need to have the line trace at all time, at least when I’m close enough. There’s probably a more… optimized way to go about it but I’m still in the beginning of “scripting” that specific part of the blueprint so I know things will change a lot. If you have an idea, could you please share it with me?

As it is, you answered my question very efficiently. Thank you very much :slight_smile:

There’s probably a more… optimized
way to go about it but I’m still in
the beginning of “scripting” that
specific part of the blueprint so I
know things will change a lot. If you
have an idea, could you please share
it with me?

Taking into account that the player may want to look and interact with more than one object type (staring at just lifts would get boring quickly), and doing a hundred of cascading cast to Thisfailcast to That then is something you may want to avoid, you can take advantage of an interface.

It’s a form of communication that is especially useful when interacting with unrelated object types. Imagine the player looking at a lift and a car. These two would be 2 different object classes that share nothing. Apart from the fact that both can be Used by pressing E.

So you create an Interface and add it to all objects that need it. Player looks at an object and presses E to Use it. Both the lift and the car can implement their own versions of the call. If the player presses E while looking at something without an interface, nothing happens.

It’s a bit simplified but that’s the gist.

If you wanted to take @Everynone suggestion further I have a couple videos that may help you. The first goes over using line traces to interact with objects, through pressing “E”, video #28, (which you seem to have gotten partially down). The second discusses how to use interfaces, video #24. Check them out and see if it clears some things up for you.

Oh. Oh… Oh my! Wow. I don’t even know what to say. It opens up so many doors! It’s so cool, thanks to you both. (However I am sad that I have to finish this in a few days (school exam) as I won’t have the time to fully dive into it right now).
Anyway, thanks a lot to both of you. You gave me a specific, clear answer with external helping links, which is about the best thing you can do. Thanks again.