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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Changing a Value a Specific Rate in Tick

I just moved to ue4 from Unity just about two weeks ago and I'm still trying to find my way around ue4 system. I have quite a bit of experience in programming including c++. I am having this problem that only seems to occurs in ue4. I tried the same code in Unity and it works perfectly.

 void AShooterWeapon_Instant::Tick(float DeltaSeconds){
     if (VertcialMovement > 0 && HorizontalMovement > 0){
         //@ 500ms VertcialMovement and HorizontalMovement Should Be Zero
         float StepSizeVertical = (TotalVertcialMovement / 500)*(DeltaSeconds * 1000);
         float StepSizeHorizontal = (TotalHorizontalMovement / 500)*(DeltaSeconds * 1000);
         VertcialMovement -= StepSizeVertical;
         HorizontalMovement -= StepSizeHorizontal;

Vertical and Horizontal Movement are set to the values of TotalVerticalMovement and TotalHorizontalMovement in another method. TotalVerticalMovement and TotalHorizontalMovement contain values that are some positive numbers that might or might not be the same. For some reason when finding the delta time from when Vertical and Horizontal movement are set to when they are 0 takes about 123ms rather than 500ms. Any ideas why this is not running the way I believe that it should?

Product Version: UE 4.8
more ▼

asked Sep 01 '15 at 06:22 PM in C++ Programming

avatar image

30 2 8 11

avatar image mrooney Sep 01 '15 at 06:47 PM

I see nothing about this that should be broken other than your equations being more confusing than they need to be. Have you tried just setting some breakpoints to see if the values are what you'd expect?

avatar image iWig Sep 01 '15 at 10:35 PM

The values that the math is giving are correct but I may have found the issue. I added this line of code: UE_LOG(LogTemp, Warning, TEXT("Time We Ran Tick: %f"), (GetWorld()->GetRealTimeSeconds() * 1000));

Now I am getting 4 log statements all with the exactly the same time in ms out to 6 decimals places. Then DeltaSeconds later, 4 more at that time. It seems that tick is being ran 4 times all at the exact same time? Any ideas on what might be wrong here?

avatar image iWig Sep 02 '15 at 12:32 AM

Ok, I have figured out what is causing the error but not sure why it would cause it? I'm using the shooter demo as a way to learn how ue4 works. I have set up multiple weapons that are using ShooterWeapon_Instant class. Depending on how many weapons changes the number of times that the tick runs. (once for each weapon) First, why would the inactive weapons still have their tick called? Secondly, why would one weapon affect another weapons?

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

2 answers: sort voted first

What does the ShooterWeapon_Instant class actually do? Are you ticking it from the weapons' Tick function? How are you making the other weapons inactive? Are you using SetActorTickEnabled?

more ▼

answered Sep 02 '15 at 01:55 PM

avatar image

703 40 32 123

avatar image iWig Sep 02 '15 at 02:02 PM

I just solved the problem. Thanks for spending the time running through my issues with me. Basically the objects are not set inactive like I thought. They are actually just having their visibility turned off. It was the interaction of each weapon's Movement Variables (TotalVerticalMovement,TotalHorizontalMovement etc.) that was causing a problem. So I went ahead and set those variables as protected and it is now working as it should.

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

I don't know how tick works in Unity and waht you expect from it, but i can explain you how Tick works in UE4 so you can setup your code to it.

Tick executes on every frame, it a function made to update actor state for a next frame. as there 0 guaranty that you gonna have stable frame rate, the changes made inside tick need to be time corrected thats what DeltaTime (DeltaSecounds) is made for. It outputs estimated time between frames, if you scale value that changes something (delta) with delta time, that delta becomes "change per sec" value. So for example

 X += 5 * DeltaSeconds;

X gonna increase it's value 5 per secound and in half secounds it gonna be around 2.5

If something gonna choke in engine and cause lack of tick for longer time, if i rember right over 400ms it will give you maximum delta time of 400ms, in other words simluation virtually gonna pause for moment (which is good thing because player after frezze would jump in time, insted it only jumps 400ms), but all objects gonna recive same delta time so everything gonna be in sync in such situation.

DeltaTime is also importent for time dilation feature of UE4 which let you scale flow of time, it works by manipulating delta times, when engine gonna decrease delta times things gonna go slower.

more ▼

answered Sep 01 '15 at 06:42 PM

avatar image

36.6k 931 169 1111

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

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

Answers to this question