How do I display the value of a timer variable on a widget?

I’m making a simple racing game, and i’m very new to Unreal.

Firstly, how would I pause a timer (thats counting up in integers) on the event of overlapping a trigger box.

Secondly, how would I then display the current integer being shown in a text box on a widget?

I think for your first problem, you want to look into ‘cast to’
Second in the Widget BP create a text somewhere and bind it to the timer variable.
You can learn more about both in various tutorials and projects on the marketplace.

I’ve found an example of a binding someone else has made, linked below, the problem is I don’t know how to get the node where there is a target socket on the left and the variable name next to a socket on the right.

Someone else’s example:

@Ed_S this is the same issue you were having on this thread…I was helping you there. If something wasn’t clear you should have said so, I made new screen shots for you that walk through the whole process. Yes you can also create a binding it is more straightforward. Just click on your text box and select “create binding”, then bind it to whatever variable you wish. You will need to reference that variable somehow within the binding itself though.

Here is the other post

Haha that’s funny/odd! But to answer your question, it is very difficult to get variables from the “level” blueprint as you can’t “cast to” it. If you wanted to have the timer in the level blueprint then you would need a method more like what I outlined in the other thread. You would need to “cast to” the blueprint that created the widget. If you create both in the level blueprint then you are good. Just take the reference from the “widget” you create in the level and pull the text variable out of it and update it to equal “Time Counter”

Sorry if i’m being unnecessarily difficult, I don’t mean to be, but like I said I just need a way to get that node with the ‘target’ and ‘variable’ (integer) sockets. You said I need to reference the variable somehow but I don’t know how, I know I can’t just copy and paste it because the blueprint “doesn’t know the references property”. The variable for the counter I have is just called Time Counter and I made it in the level blueprint (not as a local variable).

Also I don’t recall creating this thread so i’m not sure why there are two questions by me that are only worded slightly differently.

Here you go man enjoy!

Really helpful tutorial, just one thing, my timer won’t stop when overlapping my finish line trigger box. I followed the video closely, can you see anything wrong?

Print a string from the false and one from the true off the branch and see if that’s the problem. Then check and see if the player ref is the same as the character you’re playing with. Make sure that cast and variable are the same as the player character crossing the finish line.

Sorry for such a slow reply; doing other assignments. Thanks for the help. One last thing, how could I make it so crossing the start line (after stopping the timer with the finish line) the timer is reset and starts again at 0. I’ve tried to do it myself but the new timer appears over the current one making it unreadable.

That sounds like you are “creating” a timer widget each time you start a race or something. I always create widgets once and toggle the visibility for exact issues like this. You should only ever have one timer widget. So you should create it in the player or level blueprint and then it is easy to modify. So on overlap of the start position set timer to 0 and you should be good. Don’t create a new widget.

Did you ever get the timer to stop? I assume yes since you aren’t asking how to do that anymore haha

Yeah, I got it to stop. I’ve tried using the “Set New Time” socket on the stopwatch but that doesn’t help. And I have it so when I cross the start line again (when I want the timer to be set back to 0) the timer just carries on from where it stopped (when hitting the finish line). What easier way is there of simply setting it to 0?

P.S. I have the stopwatch in the level blueprint.

Nope! That’s a completely unrelated pin. You want to set the “time integer” we created back to 0. That will reset the race timer. So whatever you are doing with the “time” after we stop the counter so say the player took 15 seconds to cross the finish line. Obviously you want to use that number for something hence why we displayed it to the screen initially. But once you are done doing whatever and you want the timer to go back to 0, whenever that point is before you start a new race, “Set Time” (the integer variable we created) to 0 and you are good to go. Run the stop watch again it should count up from 0 now.

I’ve got it all sorted now, sorry for the hassle thanks a lot for the help.