I added Tick() to my character for health and stamina regeneration ect. It appears that the Tick() function ticks very quickly, almost every 1/10 second. I was wondering if anyone knew exactly how fast it ticks and if it is possible to change it to tick once every second?
MyGameCharacter.h
virtual void Tick(float DeltaTime) OVERRIDE;
MyGameCharacter.cpp
AMyGameCharacter::AMyGameCharacter(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
PrimaryActorTick.bCanEverTick = true;
// Set size for collision capsule
CapsuleComponent->InitCapsuleSize(42.f, 96.0f);
// set our turn rates for input
BaseTurnRate = 45.f;
BaseLookUpRate = 45.f;
Health = 1000.0f;
Stamina = 100.0f;
Energy = 100.0f;
Shields = 0.0f;
IsSprinting = false;
...
}
void AMyGameCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (IsSprinting == true)
{
Stamina -= 0.2f;
if (Stamina <= 0)
{
EndSprint();
}
}
if (Stamina < 100)
{
Stamina += 0.1f;
}
}
The Tick function executes once per frame regardless of your framerate. The higher your framerate the more ticks you will get per second. You may want to look at using a Timer that you set up in the BeginPlay function.
@ Marc Audy Thanks I got it working perfectly! The example shows using the GetWorldTimerManager(). I was wondering how I would go about creating custom timers instead of using that one for everything?
I am getting an error in the .cpp file when I try to set the timers. it says
12 IntelliSense: call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type c:\Users\jeffd_000\Documents\Unreal Projects\MyGame\Source\MyGame\MyGameCharacter.cpp 60 2 MyGame
You just need one timermenager instance which is actually generated by the engine (you can get it via GetWorldTimerManager()
). Individual timers are assigned to function pointer (2nd argument) to each individual object (1st argument), note that operational functions in timer manager always ask you for those two, they need that to know which timer you refereeing to.
Also if you want to comment to anwser use comment don’t create your on anwser which is extra question