BreakHitResult Branching (Interactive Crosshair)

Hello there!

While learning the basics of blueprints, I got stuck with one strange thing. What I’m trying to do is to change the crosshair image when the player gets close to an interactable object (door, in particular). I use LineTraceByChannel method, that works perfectly fine with the door animation. So I decided to copy-paste it for a new task.

But it works only partially: new crosshair appears when I am near the door, but then remains and do not disappear. I understand why. There’s no branching after LineTraceByChannel node and its EXEC pin is connected directly to the custom made Crosshair_change event. But… how can I branch it? The HitActor pin can only be connected directly to a target, as it is Actor Object Reference. And the Branch node does not work with that.

Is there a way to branch HitActor pin to tell the script that when there is no raycasting interaction with the door, the crosshair image should not be printed? I tried to find some other ways of solving this puzzle, including an entirely different method of working with crosshair images, but found nothing.

It’s important to mention: I am new to programming and blueprint logics, so to me it is still very hard to come to solutions, that may seem obvious. My apologies for such questions. Thanks!

Probably, I did something wrong, because even with does implement interface node the HUD widget image appears, but do not disappear after going away from interactable object.

Oh god, I think I finally worked it out! Thanks a lot mate, that was really helpful and on time!

I’m assuming your interactable objects have a BP interface? If not that’s the way to do it.

Then, when your trace hits something, you can check ‘does it implement the interace’? If it does, change the crosshair otherwise change it back. Here’s my trace:

( the line trace macro is just what you have here basically )

The crucial thing is the ‘does implement interface’ node.

You have to put the code to turn off the widget on the false branch of the IF :slight_smile:

Hey ! I wanted to know if your interactive crosshair work correctly ?
If yes, would it be possible to have an explanation or screenshot of your blueprint ?
I keep searching and trying to understand, I can’t make an interactive crosshair …

Thank you ! :slight_smile:

Hey ! I wanted to know if your interactive crosshair work correctly ?
If yes, would it be possible to have an explanation or screenshot of your blueprint ?
I keep searching and trying to understand, I can’t make an interactive crosshair …

Thank you ! :slight_smile:

Basically, it’s composed of two things:

  1. A widget that zooms in and out

  2. A line trace from the camera, that when there’s a hit, zooms in. And when there’s no hit, zooms out.

Thanks for your answer !

I was searching to replace my actual crosshair with another while being over an interactive object. I already have my line trace. But my problem is to switch from a crosshair to another.

In my widget there the crosshair when I’m over an interactive object, and in my HUD, there’s the normal crosshair

PS : I’m still a noob with blueprint, I’m trying to learn and understand.

You have to do all the crosshair stuff in one place.

When the object is interactable draw crosshair A, otherwise draw crosshair B.

This is all I have:

So if it’s a blocking hit do one ch, otherwise do the other…

( I don’t return a hit from the function, unless the object implements an interface.

I did it, it work but same as above, the crosshair is not replaced but just add to the other one and I can’t use the “remove from parent”

Are you adding the widget right after the line trace code?

Then you have a reference to the widget and can remove it before adding the other one.

Sorry, I don’t know your setup…

Here is my setup, I hope it help you. Thank you very much for taking your time to help me, really.

So, put those references coming out of the widgets into variables:

and when you do one, you remove the other:

Tell me if you get stuck…

It still do the same, the second crosshair appear but the first one doesn’t disappear (and the second one too when I’m not on an interactive object)

You’re nearly there, but you’ve got the logic wrong. When the item is useable you need one ch, otherwise the other ch.

At the moment your code says ‘if item it useable, swap ch’

See what I mean?

Ditch that swap concept. Just do one or the other.

Like this:

( except normal and select the other way around ).

I will be a stupid question but … what do you mean by “ch” ?

Crosshair :slight_smile:

If you meant like this, I already tried but it doesn’t work, I always have the message you see under that appear

Sorry, my bad. Had a bit more time to look at this. It doesn’t work because even though the widget is remove, it still exist and the variable is valid.

Visibility works much better. Put this on begin play:

Then you can swap on tick with: