x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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: alt text

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. alt text

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

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!

Product Version: UE 4.21
Tags:
fps.png (147.5 kB)
2.png (46.9 kB)
3.png (990.3 kB)
more ▼

asked Jan 10 '19 at 12:52 AM in Blueprint Scripting

avatar image

butavpaul
17 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

alt text

capture.png (164.5 kB)
more ▼

answered Jan 10 '19 at 01:25 AM

avatar image

ThompsonN13
10.1k 33 9 23

avatar image ThompsonN13 Jan 10 '19 at 01:29 AM

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.

avatar image butavpaul Jan 10 '19 at 01:31 AM

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.

avatar image ThompsonN13 Jan 10 '19 at 02:04 AM

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.

avatar image ThompsonN13 Jan 10 '19 at 03:15 AM

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.

avatar image ThompsonN13 Jan 10 '19 at 03:51 AM

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.

alt text

alt text

capture.png (353.5 kB)
capture1.png (376.3 kB)
avatar image butavpaul Jan 10 '19 at 08:06 AM

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

avatar image butavpaul Jan 10 '19 at 09:23 AM

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.

avatar image ThompsonN13 Jan 10 '19 at 03:00 PM

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.

avatar image dabs863 Jan 10 '19 at 02:14 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question