Download

Need help with using timer in Character class in Unreal

As the title says I’m looking for a bit of help with Timers as I’ve never used them before and need to implement one within my project.

So what i’m trying to do is start and end a timer after a few seconds, I want to get the players location before it starts and after it ends to be able to predict where they could potentially be after that same amount of time again but I have no idea how to set this up, I’ve tried looking at tutorials but they don’t seem to help much.

Any help would be appreciated, Thanks.

Hi xBosworth,

Have you taken a look at the documentation for SetTimer? https://api.unrealengine.com/INT/API/Runtime/Engine/FTimerManager/SetTimer/5/index.html

Happy to help more if there is something specific that is confusing. Just don’t want to be too redundant :slight_smile:

You can read about Timer’s here:
https://docs.unrealengine.com/en-US/…tecture/Timers

However, If you’re just trying to predict player movement, you can skip the timer and just use their linear velocity + forward direction.



FVector PredictPlayerPosition(AActor* Player, float Time)
{
   check(Player);
   FVector PredictedPosition = Player->GetActorLocation(); // Default to our current position.
   if (UPrimitiveComponent* PhysicsComponent = Player->GetComponentByClass<UPrimitiveComponent>())
   {
      PredictedPosition = Player->GetActorLocation() + (Player->GetActorForward() * (PhysicsComponent->GetPhysicsLinearVelocity() * Time));
   }
   return PredictedPosition;
}


… same time Jinx lol

Thanks a lot for the help, i’m assuming using Check(Player); would be the same as using if(Player){ } ?

Yea, check is just an assert if that logic is null (in this case “Player”) meaning whomever is calling that method should make sure Player is valid before passing it in, but you can use an If check instead.