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"

[Closed] How to use Delta Time?

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.

Product Version: Not Selected
more ▼

asked May 03 '14 at 12:15 PM in Blueprint Scripting

avatar image

434 40 40 46

avatar image shimozurdo Dec 12 '15 at 05:49 PM

very useful thanks guys!

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

The question has been closed Sep 03 '16 at 12:13 PM by Kenomica for the following reason:

The question is answered, right answer was accepted

2 answers: sort voted first

Here is what you need.

Store the Delta Seconds in a float and now you can work with that value.

alt text

deltatime.png (31.4 kB)
more ▼

answered May 03 '14 at 01:37 PM

avatar image

176 10 12 21

avatar image Kenomica May 04 '14 at 07:19 AM

thanks for all the help, I'm totally new to this side of things.

Is this correct? alt text

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

delta.jpg (59.1 kB)
avatar image Dieselhead May 04 '14 at 09:44 AM

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.

avatar image Kenomica May 04 '14 at 11:33 AM

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.

alt text

delta.jpg (56.2 kB)
avatar image mindfane May 04 '14 at 10:20 AM

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.

alt text

blp.jpg (103.8 kB)
avatar image Kenomica May 04 '14 at 11:38 AM

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.

alt text

intcompare.jpg (51.3 kB)
avatar image mindfane May 04 '14 at 03:13 PM

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.

avatar image Kenomica May 04 '14 at 03:41 PM

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.

avatar image mindfane May 05 '14 at 07:31 AM

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 '>/

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

avatar image Kenomica May 06 '14 at 08:00 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
 Value += Speed * DeltaTime;

You scale varables that will change something by delta time, end that varable becames chnge per secound

more ▼

answered May 03 '14 at 12:37 PM

avatar image

36.6k 932 169 1111

avatar image Kenomica May 03 '14 at 12:51 PM

Thanks for the reply, I should have mentioned I'm using blueprints though.

avatar image Shadowriver May 03 '14 at 01:20 PM

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

avatar image mindfane May 03 '14 at 01:28 PM

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

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

Follow this question

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

Answers to this question