Mouseover on an object but not from too far in the viewport

Goog evening,

I have created a code that, when I place mousecursor on a mesh displays a text in a widget : when I roll over a statue il displays the text associated to that item to explain the art behind the statue, however I noticed that even when I am very far from the statue, when the mouse rolls on it, it displays the text : I want the text to be displayed only when the player is very near from the mesh, could you please help me with that ?

Thank you very !

You can do this quite easily by checking the distance.

Go into your widget, and bind a new event to visibility.

You can then make a simple distance compare system in that function you just created.

You should set HolderActor to the actor that this widget is associated with (ie the statue). Distance to show is the maximum distance away that you can still see the text. You probably want something like 300 or so- plus or minus a few hundred.

I see… I will test it tonight, thank you very much, and if it works I will close the topic.

However, if I want to associate not the mousecursor but the mouseclick, I mean if I want to be able to click only from a distance, do I have to replace “GetActorLocation” by “GetMousePosition” and associate its target to the playercontroler ?

Alternatively, if you’re using mouse over events as the line above suggests, in the Player Controller:

image

This way you do not need to check distance every frame. Things far out are simply out of range.

You are my hero :slight_smile: Solved !