Activate button after 3 seconds looking at it

I’m developing for GearVR, and I need a interface that activates after the target is on the button for 3 seconds, I can’t use an input such as a click because I want to develop a product totally “clickless”.

I have no idea where to start the blueprint, but the logic that I have in mind is:

Create a Timer that add +1 each second that is overlapping the button
If the target goes out of the button it resets the timer
After 3 seconds it changes the canvas image

Thanks :slight_smile:

I suspect this won’t be your last “look at” mechanics, so create common line trace to track what player is looking at

https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseRaycasts/Blueprints/index.html

Keep what player is looking at in varable, if you detect change (what line trace return does not match varable) call function to object in varable that it not being looked at now and to new object detected (if there is any) inform it at it being look at with function, It would be good if you create base class for all interactivables, or interface if you want to involve Pawns too, which will have base function (event in case of base classes) stoped look at and start looked at which trace code can call. Thats just one way of doing that, you could make timer in trace code too and make trace code call Use function in object.

Does it [raycast] work with widget elements? I would like to make buttons floating on a wall. Or should i go to static meshs as a better option?

[and thank you for answer, it is helping a lot!!!]

I don’t think ti will work on widgets but on there place you can put Box Component to detect collision that will work with raycast

Can you show me how i should create the blueprint for the collision being reconignized or act as a trigger?

Ty

Well i gave you link to doc how to do trace, in order to trace you need actor to have something to collide and that can be any shape component (box, shere, capsule components), you can fine tune positioning of components using relative location and rotation

Yeah, after 2 hours i got the right way to use trace [not a programmer so i have some troubles doing it], but i still don’t get how to use a timer to trigger an action…

I mean if my raycast stays over a button X seconds trigger " print string A"

i shoul create a variable and stores the time to trigger or there is a node/function to do this??

ah so you don’t know about timers?

https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseTimers/Blueprints/index.html

I saw them on api but i have no clue how to start this logic or with node i should use… At this moment i have this:


Basically only the raycast done… I know that timers will help me with creating event that plays after some time, but how to create a check if still colliding +1, if not reset the timer, in a variable until it is equal to 5 then trigger the event?

I don’t kinow if my problem is logic or just don’t know enough about blueprint…

Try this! I made this using 4.10.3
Start with a brand new FPS template.

Set up the button:
1-Create a new blueprint. Add a mesh/sprite/etc for the button you want the user to look at.
2-Add collisions to the blueprints I want to respond to when looked at. Box, sphere, capsule, any shape is fine.
Use whatever matches your mesh.
3-Now select the collision.
4-Under collision presets, select CUSTOM.
5-Now choose an Object Type. Pick a type that you aren’t using anywhere else. I chose “Vehicle.”
Ignore everything else and set Vehicle to Block.
Be sure that Generate Overlap Events is also enabled.

Here’s the Event Graph for the button:

You need a minimum of 3 custom events.
Star Timer, Clear Timer, Activate Button.
You need a branch to check if the timer is active, otherwise you’re going to keep re-activating it and it’ll only go off if you hit it once then don’t activate it again until it’s run.
Took me a little while to figure that out.

Set up the Player Character:
Set the player to do line traces for objects every tick.
I use the camera location for the start and then the forward vector x 5000 for the end.
5000 is a length I chose, change it depending on what you need.
Make the ENUM array by promoting Object Types in the Line Trace to a variable.
Select Vehicle if that’s the channel you chose earlier.
Ignore Self is checked.

Create a branch for Return Value.
That value is false if you didn’t hit any buttons. If the line trace is not hitting any buttons it should reset the timer.

If there IS a hit, then check to see if it’s a button by using Break Hit Result and casting the hit actor to the button.
From the cast node where it outputs “As BP_Button” be sure to drag to an empty part of the graph and search for Start Timer custom event.
Do that again and search for the Clear Timer custom event.

Compile everything.
Place buttons in the world.

Have fun!

Hi, I realize your question is pretty old but I posted something that works for me as an answer to the original question.

I hope it helps you.

If you need I can send a sample project.

Hello, thank you for your solution! It helped me much. However, I found a little bug: in your BP, you destroy the Actor itself, so you probably don’t notice that the “ActivateButton” function keeps being called forever if I keep staring at the button. (in my code, I was doing something else with the button, so I noticed this). A simple boolean flag solves the problem:

I’m very pleased to hear that my reply helped someone! :smiley:

Thank you for catching the error with destroying the button. I was not sure if the original poster wanted a single or multi-use button.
I realize I should have put a Print String that just said “Hello World” so the OP would know that this is where he or she is supposed to modify my answer to suit their needs.

If you want to be able to hit multiple buttons at the same time, replace Line Trace with a Multi-Line trace and insert a For Each Loop between the trace and branch. Break hit result for each array element.