I have an Actor Component class attached to my Character. More specifically, it is a combat combonent, used for combat-related code. UE Version is 5.3.2
The TickComponent function is not being called. I have a UE_Log and an AddOnScreenDebugMessage being called here, and neither of them are being called at all, let alone every frame. The rest of the code in this component class is working just fine, but tick isn’t.
In the Component’s constructor, I have bCanEverTick set to true:
PrimaryComponentTick.bCanEverTick = true;
Everything is correct in the header file CombatComponent.h:
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
And Super is called in the .cpp implementation:
void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(
-1,
15.f,
FColor::Cyan,
FString(TEXT("Combat Component Tick called"))
);
}
UE_LOG(LogTemp, Warning, TEXT("TickComponent Combat"));
SetHUDCrosshairs(DeltaTime);
}
This should call the UE_Log and DebugMessage every frame, but for some reason it isn’t.
I actually learned from a comment on the course I’m learning from that this is a bug related to the constructor.
Lets say you have a character class.
On the character class’s constructor, you construct the Combat Component:
Combat = CreateDefaultSubobject<UCombatComponent>(TEXT("CombatComponent"));
and set it to replicate:
Combat->SetIsReplicated(true);
Apparently, this causes TickComponent on the Combat Component to stop working (again, this is just an actor component).
And the fix is to remove/comment out those constructor lines on the character class, re-compile, then re-add/uncomment those lines, re-compile, and the tick function will start working again.