I’m currently in the process of taking my game from prototype to Alpha; one of the things that requires is changing the event ticks, since currently gameplay and mechanics can vary depending on the frame rate.
I know you can use delta time to set the tick rate as a constant, but I’m completely lost on how to do this.
Any help would be appreciated.
It’s the same, just multiply things with deltatime i know some movement function in BP have scale input, you can use that instead too
Value += Speed * DeltaTime;
You scale varables that will change something by delta time, end that varable becames chnge per secound
Thanks for the reply, I should have mentioned I’m using blueprints though.
In BluePrint, you have the ‘Event Tick’ node. It has a ‘Delta Time’ output connector. Use it for further calculations, that might depend on it
Here is what you need.
Store the Delta Seconds in a float and now you can work with that value.
thanks for all the help, I’m totally new to this side of things.
Is this correct?
Also, this of course makes the character move extremely slow (which is where I imagine multiplication comes in) - but how would I set up the maths side to basically make delta time speed the same as it was using event tick at fixed at 60fps?
Also, how would this work for blueprint nodes that do not have a float input?
Thanks for all the help
When you multiply something with delta time that value becomes “units per second”. In your picture here the Forward vector will look something like (1, 0, 0). That means it moves 1 unit per second. UE4 uses 1 unit = 1cm by default and that’s why it’s moving slow.
And of course if you multiply a rotation rate with delta time it becomes degrees per second.
Ideally you should have variable whcih defines the Rate (in this case MovementRate) whcih is the change per second. You multiply that variable with delta time and this will give you the actual amount of change.
Here is a small example. You should adapt it to your need. In my example, the variable CameraMoveSpeed defines how fast camera moves (ie cm/sec). I multiply it with delta time (Get World Delta Seconds) and feed it to AddMovement node.
That’s incredibly useful, thank you.
Currently I am multiplying movement speed (variable set to 120) by delta time, which seems to give the result I was looking for. Essentially the same speed I had when using the event tick the standard way.
The visual is extremely useful, thanks. Also, I never realised you could access Delta Seconds that way, which has helped a lot. (See above comment with image)
Is there a way to use this with a node that does not take float or rotation inputs?
For example, I have an event tick comparing two integers. Although not as game breaking as say, movement speed varying, is there a way to also use delta time for this?
I’m 100% new to coding - I love blueprints but when it ventures in to coding territory I’m a little stumped.
I don’t quite follow. Could you elaborate it further?
What are you trying to achieve here. I see that you are doing a comparison, and you have not specified what to compare with. Are you trying to compare Delta Seconds against an integer?
Blue-prints support casting one type of variable to another (this is not alwsy possible when objects are involved). But you can convert between floats and integers.
This may just simply be my lack of understanding delta time overall.
What I’m doing here is comparing the number of bananas the player has collected with zero. So, more than 0 sets the bool “has bananas” to 1
Less than zero means they have none, so it sets the bool to 0.
This is used as a system for obstacles the player can hit, if “Has bananas” is false, the player dies, if it is true, they lose the bananas and live.
The event tick controls this, and if I am correct, the comparison is made every tick / frame, which can vary per player / computer / performance.
So what I’m hoping for is a way to set the tick rate to a specific rate that is not based around frame rate, as with the movement speed etc, earlier.
Actually you only need to update the HasBananas variable only when you either acquire or lose a banana. You dont have to do it every tick - unless ofcourse you gain/lose banana over time (ie you get a banana every 5 seconds…).
I cannot answer this with 100% accuracy since I dont know how you have implemented the rest of the system. So I am giving you a simple scenario and how I would do it:
- You gain a banana when you touch a banana (bananas are present in the world as pickup items)
- You lose a banana when you suffer a damage.
So here, I will increment BananaCount and update HasBanana to TRUE on the function Hit and decrement count on TakeDamage (and possibly set HasBanana to false, based on a ‘>/<’ condition (type ‘greater than’/‘less than’ in blueprint).
Unreal calls the Tick() function once in every frame. I dont think you can alter this.
Ideally put only those code that you need to run continously inside Tick() function. Code that needs to be executed on an particular event should be moved to appropriate event handlers (eg: Touch, Key Press, …)
About delta time:
Liek I said, Unreal calls the Tick() function on every frame. In an ideal case it will be called 60 times per second. But that is not always the case. Sometimes your code might take more CPU time and result in fewer ticks per second. So you cannot assume that the duration between each Tick() is the same. To counter this, Unreal will pass the time elapsed since last time Tick() was called. That is ‘DeltaTime’. YOu only need to use it when you logic depends on time passed (like a spell recharge logic, where player must wait a certain time unilt he can use a spell again…), or update some variable based on change rate
Thank you, that was very interesting and helpful to read. It’s certainly allowed me to fully understand how event ticks work, as well as delta time.
Initially that is how I had it set up, the engine checks the banana count on collision with the object - if it’s zero, they die, if not they lose bananas and are launched backwards, to try the jump again.
But I had an issue that it would cause the events to fire twice, since it seems the blueprints fired too fast. The collision would be checked twice so the player would die no matter what.
The blueprint would check, see bananas, minus them, check them again then destroy the character. So the collision was happening multiple times before the character was being launched.This is why I had the check set to event tick. However since taking a short break from working the solution hit me.
I added a DoOnce node at the start, that was only reset by the final node firing and a 0.2s delay - which fixed it.
The event tick was a lazy way of fixing it which I guess was not ideal for CPU usage etc. Thanks for the great help. I understand things a lot more now.