Line trace by channel show widget

Hi. I’m trying to interact with an object using line trace by channel but first I want to show a widget with a button for interaction. The problem is that when I’m over an object line trace is firing multiple times and my widget is created as long as I stay over the object.
I’m using BP interface, so in my FPSChar BP I have this:

Here is my object, which is a door. Here I don’t know how to stop creating multiple times the widget. And after I hover out the object, the widget should be removed from viewport.

This is how is working now. ( Widget created multiple times )

How can I show the widget only once if I’m over the specific object and to be visible until I press the widget button or I hover out the object.
Thank you!

why not just use overlap events? it seems like your just trying to show the widget when your overlapping the actor so using overlap events would be logical. you would just need to have on begin overlap, then a bit of flow control to make sure its the player, then the creation of the widget and set a variable reference to the widget created. then on end overlap you see if the variable is still valid, if it is valid then you destroy it, if its not valid then youve already destroyed it by clicking the button. its pretty simple and theres a example script posted below. it will also perform better this way since it doesnt rely on tick.

if you really insist on using tick then you could easily just have a do once node at the beginning of the script just before your print string. then have a sequence node after and have the second pin loop back to the reset pin on the do once. this method is not recommended however since again its not stateful so less performant and looping back is bad practice from what ive heard and experienced. just my thoughts on the subject though so its up to you.

Thank you for your answer. First I’ve used overlap events but now I want to open for example a drawer or to pick up a key, so I’m trying to do this with the line trace, because I want to interact with the items only if I’m facing it.

try a do once node and the reset it when close i never dealt with line trace for me overlap event is the best way but the do once node might do the trick

thats fine but i would still suggest at least looking into using a timer since it should perform better and will be reliable. personally the tick delay combo i think is poor practice and well lets just leave my opinion portion at that haha.

oh and using the do once only really helps one half of your issue, the part of the widget being created multiple times. it doesnt solve the issue of destroying the widget when you look away. i did see a stream a few months back about making a slider where they used a similar style to yours and they basically did a test each trace to see if the object hit was the same. if the object was different then you call an event and set the new object as the current one.

i was bored so heres an example of what i was mentioning.

if you look at picture two below you will see that on hit we compare to see if the actors are the same if they are we just call interact, if they arent the same then we call the done interfacing event then set the looking at variable to the new actor.

picture one shows one way that you could setup the script for the actor your looking at. here we just check can i interact with this? then we see if the widget is already created if it is we do nothing, if not we create the widget and set the variable reference. then on the done interacting event we again see if the widget is valid and if it is we destroy it. i added in the interactable bool check so that if you press the button on the widget you could make it so the widget doesnt come back up immediately. but if you leave and reapproach the actor it will be interactable again.

Thank you mate. I’ll try it now and I’ll get back to you! Thank you again!

It’s working perfect! Thank you!
Up there you said that this is not a very good practice. For future use, should I use box collisions only? If yes what if I have 3 objects in the same place? How can I use for each object a different widget for exameple. Thank you! I’m at beginning and I’m trying to figure out the best practices.

you said that this is not a very good practice. For future use, should I use box collisions only

what i was really getting at was to avoid tick whenever possible since it becomes expensive quite quickly. for your case a timer is sufficient since your looking to fire your script 5 timers per second.

what if I have 3 objects in the same place?

having overlapping objects does become a problem. there is ways around that but for now i think your solution works well enough.