I have a custom C++ component derived from UActorComponent. This is added to various actors. I want to disable ticking on that component so I can handle that manually. But I am not able to do so. Despite deactivating ticking on the component it gets re-activated every frame.
How can I disable the automatic ticking of the TickComponent() method of the MovementComponent?
MovementComponent Constructor:
UMovementComponent::UMovementComponent()
{
// Tried many ways found on the Internet to disable ticking, none works
PrimaryComponentTick.bCanEverTick = false;
PrimaryComponentTick.bStartWithTickEnabled = false;
PrimaryComponentTick.SetTickFunctionEnable(false);
SetComponentTickEnabled(false);
}
SomeActor Constructor:
SomeActor::SomeActor()
{
// Movement Component
MovementComp = CreateDefaultSubobject<UMovementComponent>(TEXT("Spaceship Movement Component"));
MovementComp->PrimaryComponentTick.bCanEverTick = false;
MovementComp->SetComponentTickEnabled(false);
MovementComp->PrimaryComponentTick.SetTickFunctionEnable(false);
AddOwnedComponent(MovementComp);
}
SomeActor Tick:
SomeActor::Tick(float DeltaTime)
{
// Only works if called every frame. Comment the following out and the MovementComp gets ticked again.
MovementComp->PrimaryComponentTick.bCanEverTick = false;
MovementComp->SetComponentTickEnabled(false);
MovementComp->PrimaryComponentTick.SetTickFunctionEnable(false);
...
}
Setting PrimaryComponentTick.BCanEverTick will not work instead PrimaryActorTick.bCanEverTick has to be set. Also with the default constructor wit ill not work, bCanEverTick has to be set in the UMovementComponent(const FObjectInitializer& ObjectInitializer) constructor instead.
PrimaryComponentTick is for the ComponentTick(float DeltaSeconds) function while PrimaryActorTick is for the Tick(DeltaSeconds) function.