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?

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?

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.

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”), (()->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?

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?

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?

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.