Tick fucntion in C++ does not fired in my program?

this is my code and my Debug sphere don’t even appear??Itried to make a UE_LOG () to see if my tickfuntion work but it didn’t? My blueprint doesn’t work either? Did i did something wrong that bug my program??

AItem::AItem()
{
PrimaryActorTick.bCanEverTick = true;
}
void AItem::BeginPlay()
{

}
void AItem::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

	//movement rate in units of cm/s
	float movement_rate = 50.f;
	UE_LOG(LogTemp, Warning, TEXT("Hello!!"));

	//movement rate* deltatime (cm/s) * (s/frame) = cm/frame
	AddActorWorldOffset(FVector(movement_rate * DeltaTime, 0.f, 0.f));
	DRAW_SPHERE_SF(GetActorLocation());

You need:

SetComponentTickEnabled(true);
1 Like

You override BeginPlay but are missing Super::BeginPlay(). I believe this can even affect tick.

1 Like

where do i put this??

You can do it in constructor or somewhere else if you want an object to only Tick() at certain times.

As an example several projects I’ve worked on actors only Tick() when they are moving or animating.

1 Like