Download

Multiple crosshairs/cursors

Hey, I have a custom crosshair texture that is centered to my screen window, but I want this crosshair to change colour when it hovers over an enemy AI (white to red), thanks in advance!

ue4forumshelp82.PNG

You could do a line trace and check the result for a tag or class.

HTH

Thanks for the reply, should I do this in this game HUD blueprint? Because line trace has a lot of inputs and outputs so I’m not sure how to set that up

This should get you going.

You would have to have a way of getting the camera’s far plane, But my quick search did not turn up any results :frowning:

HTH

Okay I’ve made this so far (see pics attached) and when the line traces it checks if the actor has a tag “enemy” which I have given to the turret. If yes then make crosshair red, otherwise it’s white. The problem is it is always white and the print string “enemy out of sight” is constantly checking even when I’m looking at the turret. Every time I play I get an error message though which I’m hoping is the reason it isn’t working, any ideas? Thanks for the help!

ue4forumshelp83.PNG

ue4forumshelp84.PNG

ue4forumshelp85.PNG

That looks like it should work.
I can only suggest looking at different ways to tag actors.
I remember seeing something about tagging where the person was tagging the components instead of the actor, Here is the link to the answerhub question

HTH

The reason why it is not working is that the HUD class is a cosmetic class, and this sort of operation is better done in your Character class, then passing the result to the HUD class.

EDIT: Also, you are not checking if there is a hit actor. Your errors are caused by your code trying to access an actor reference that doesn’t exist. A simple Branch node off the Return Value node from the Line Trace will allow you to check whether the trace hit something or not.

On the raytrace, change the DrawChannel to Visibility.
This happens a lot to me.

Okay so I’ve created a “Trace Item” function in the character blueprint
4256b2c59c6ea3220fad6af7517326c919719129.png

After an event tick in the event graph of the character blueprint I call the function, the condition of the branch is if the actor has been traced and has the tag “enemy”, which works as it prints the string “Enemy in sight” when hovering over it yet I still get the huge list of errors when I quit.
a29f0fe2f26d83f6b41344c1d4cab990a7cf671d.png

I’m not sure what to do in the HUD blueprint now, I’ve set it back to default so it only sets the default crosshair, but I still want it to change to red if the actor traced has the “enemy” tag, is this something I do in this HUD blueprint or in the character blueprint?
d746a3630da0f9c27af639ee48e1029ae7c0d510.png

Thanks, I appreciate the help, I’m still learning blueprints :slight_smile:

After you call TraceItem, the ActorTraced variable is allowed to be null, by dint of your own code. You will need to either do an IsValid check, or add an additional exec output from your TraceItem function to signify no hit.

You errors are from Actor Has Tag being fed a null reference.

Thanks for the reply, the IsValid does check and prints the string, but it prints the string “Enemy in sight” for all actors that the players crosshair hits.
071578cedcc44d6998cd62a36dc36efa9653771e.png

Also I need a way to set up the HUD and the two possible crosshairs as currently it’s set up to only the default crosshair. I tried casting to the HUD in thecharacter blueprint and drawing the textures but I had errors, and vice versa in the HUD blueprint
9df1e687662b562169208fd04324d607f4501dd3.png

I want you to take a look at that last image of your character blueprint, and consider how you plan to determine whether the actor is an enemy or not, and what is missing from that picture. If you still can’t get it, take a look at the previous image of the blueprint.

To communicate between the Character and the HUD, create a boolean variable on the HUD to control whether you are looking at an enemy. On your character, after you have determined whether you are looking at an enemy or not, get the Player Controller, and get the HUD from that player controller. Cast the HUD to your HUD blueprint, and set the aforementioned boolean variable to the correct value. In your hud, simply use a branch or a select node to determine which image to show.

Ah okay it’s now switching crosshairs, thanks for the help :slight_smile:

Quite welcome.