To Tick or not to tick

I know this might be a bit of a trivial concern.

But I am working with a SpectatorPawn(think RTS) and working on the camera. Everything is in C++.

In the SetupPlayerInputComponent, lets say I bind something to MoveForward. Example W and D for camera to slide forward/back.


InputComponent->BindAxis("MoveForward", this, &ARTSPlayerCameraSpectatorPawn::MoveForwardInput);

Now the question is,

  1. I could fully resolve the movement in this function,

  2. I could just alter some ‘move forward’ value, that then gets resolved in the Tick function.

  3. Has the benefit of not needing a Tick function, but loses deltatime. Less clutter in Tick, potentially not needing to override and don’t need to be bCanEverTick

  4. Has the benefit of a framerate smooth transition, because now I can use deltatime, however now I have to tick and whatnot.

They both have ups/downs depending upon if there are spikes/changes in the FrameRate. I have seen both approaches used in many places. What are your thoughts on why one is preferred?

I know there are a lot of variables of why you choose one over the other. But I am having a hard time resolving what the right questions are to decide.

Hey you can get the deltatime from anywhere you want : UWorld has DeltaTimeSecond as a variable.

so in that case, I’d be better off not putting this particular thing in the Tick function, so that things are more encapsulated/modular? Depending upon my design.

Is there then a reason why the Tick function even has a deltatime parameter? If it is globally accessible. or just for convenience and to encourage use of deltatime in Tick?

Yeah for movement i would not put it inside Tick() but inside a function bound to the InputComponent.

Yeah i think you are right, you often need deltatime inside Tick().

I made an RTS camera tutorial you can find here (the corrected/extended version of the Wiki post):
imo it is better to only set parameters by the input functions, and do everything inside the tick function to be more transparent for future extensions. moreover, there it is easy to maintain frame-rate independent movement by deltatime.

I am doing something similar and want to allow both keyboard (WASD) and joystick input. I simply hold the current MovementVector in a private FVector (i.e. in MoveRight() I would do MovementVector.X = AxisValue). I then do the movement in Tick() as this allows MovementVector to be set from any of the input methods and resolved in a single place.

Either is suitable since input bindings are ticked anyway by the engine (so long as the object has a controller or is bound to a player I believe), usually they just set a property in the movement component such as an FVector or a float etc, and the MovementComponent ticks and calculates the movement based on that. This is how CharacterMovementComponent works for example.