I am trying to create an in-game clock system that is separate from the default system because the game world will run at a different time rate than the real world. In doing so, the baseline to establish the clock is to establish the minutes and seconds. Getting the seconds set is easy enough:
The problem comes in when I try to get the minute value. As you can see in the BP graph, the ClockSetMinute function is called after the seconds are set. As you can see in the next three images, all the flow control BPs will pass multiple outputs from an integer value because the Event Tick is firing multiple times per second. Even using the Do Once blue print does not keep this from triggering multiple times.
In this graph, the first branch should only fire if CurSeconds == 0, but since it is receiving multiple event triggers at sub-second intervals, it is going to fire multiple times within the 1 second where that statement is true. I added the DoOnce node, but as you can see in the graph, it is firing way more than once.
event tick() returns deltaSeconds, so if you add that to a counting float every tick, whenever that float gets greater than 1, you can subtract 1 from the count and allow blueprint flow to execute. this will result in execution once per second.
You are looking for timers. If you right click and type timer into the context sensitive menu you can get the timer node, which will allow you to set a specific interval and name the timer. Creating a custom function with the same name will create a timed event that fires off once every x seconds, where x is the number you chose.
That worked perfectly! Thanks. I still think a hard-coded 1PPS (one pulse per second) function would be a useful addition to the BP nodes collection, though.
I knew about the timers, but I was doing this as an experiment to see if it could be done mathematically with the normal BP’s using the delta time. The purpose was to create a simple to implement Clock BP that would allow designers to set up their world specific calenders as quickly as possible. Omnicypher found a great solution to it.
Maybe you can try also using delay
Or I think if thats failed. My idea is in C++ there is what you called modulus so give it a try a modulus 30 is one second
that solution worked fantastic. I made EventBeginPlay setup a timer looping every 2 seconds, then made a function of the same name to perform a command. --Thanks~!
However, timer is not perfect (and almost useless to me) since it CANNOT take any parameter.
Says, there is very possible to fire the same timer (a function/event) before the earlier timer completed, the variables in the loop will be mess up. So, gonna figure out a way to keep the references for each trigger, and that would be the hardest part here, IMO.
Updated: I found that I could create a blueprint (actor component) to do the timer event inside there, and I can pass references (variables/how long the timer should activate) to that component, so a copy of references will be created every time when I added this component and won’t be mess up with the next one during it fires again.
Hope this helps someone.