Component "bCanEverTick" has no effect

I have a custom component written in C++.
I’m trying to have the component start with tick disabled, and enable it on demand.

I thought this would be simple, but “PrimaryComponentTick.bCanEverTick” in the constructor seems to have no effect.

The only way I found to disable tick on startup, was to set “bAutoRegister = false” in the constructor. However, if I do that, calling

this->RegisterComponent();
this->Activate();

on begin play seems to have no effect. The component never ticks, even after calling

PrimaryComponentTick.SetTickFunctionEnable(true)

One work around I found was to call use

PrimaryComponentTick.SetTickFunctionEnable(false)

In the begin play function, and then use it later to enable the tick. It bothers me that this is the only way. Why does bCanEverTick have no effect?

Hey mgumley-

PrimaryComponentTick.bCanEverTick appears to be working in the component constructor for me. When set to false, the “Is Component Tick Enabled” node will correctly return false when called from a blueprint using my custom component. To enable ticking for the component, first bCanEverTick needs to be set to true, then SetComponentTickEnabled(true) needs to be called. SetComponentTickEnabled() will check if bCanEverTick is true and, if so, will call SetTickFunctionEnabled(). This is why you have to update bCanEverTick prior to calling SetComponentTickEnabled().

Cheers

Have you tried putting code into your tick function? The “Is Component Tick Enabled” function may be giving you a wrong answer.

Also, doing this check in a blueprint is not a sufficient test. My component is C++.

You did not mention code in your component tick function. I was only using the blueprint node for quick verification, changing/updating bCanEverTick and calling SetComponentTickEnabled was done through code. Additionally, the comment explaining bCanEverTick in code states “If false, this tick function will never be registered and will never tick. Only settable in defaults.” This would imply that setting bCanEverTick to false wouldn’t prevent the component from ticking even if you changed this value during runtime.

Rather than setting bCanEverTick, if your goal is to have the component not tick when spawned have start ticking sometime after runtime, you can instead set PrimaryComponentTick.bStartWithTickEnabled = false; to prevent the component from starting with tick. You can then call SetComponentTickEnabled(true); to enable ticking afterward. This was tested with an AddOnScreenDebugMessage() in the TickComponent function that did not print when I started pie but did print after calling SetComponentTickEnabled.

1 Like

Thank you for explaining how to work around this issue. I still think that bCanEverTick should be investigated though.

This would imply that setting
bCanEverTick to false wouldn’t prevent
the component from ticking even if you
changed this value during runtime

I was setting the value in the component’s constructor. Is there some other place that I need to set bCanEverTick=false ?

I understand there might be a workaround for this, but it seems to me that this is a clearly defined bug. Steps to reproduce:

  1. In the component constructor, set
    bCanEverTick=false.
  2. Override the “void TickComponent”
    function, and put a print message in
    there.
  3. Run the game, and see that the print
    message still happens, which means
    that tick is being called.

,

I just tried making a project to reproduce the issue and I made another discovery. It’s actually the new compile feature in 4.15 that’s causing the problem.

When I made a new project, I created a component and used “PrimaryComponentTick.bStartWithTickEnabled = false” in the constructor. I went to the editor and pressed compile, and my debug message in the TickComponent was still firing. After closing the project and doing a git-clean, then rebuilding, the problem was gone. It seems like a bug that the new editor compile only works on some of the CPP class. Any thoughts on this?

After investigating further, when trying to activate/deactivate a component the most consistent method to do so is to set bAutoActivate in the constructor. With this variable set to 0 (false), the component doesn’t tick (regardless of PrimaryComponentTick settings). You can then call Activate(true); or Deactivate(); during runtime to start/stop the component tick.

,
Thank you for continuing to my posts. The issue is not resolved, so please don’t mark it as resolved. Here’s video evidence that there is a bug. I made fresh project and demonstrated the bug in less than 4 minutes. In summary, the component tick settings do not take hold unless the Unreal Editor is closed and re-opened. Hot reload is failing.

I have entered a report about the behavior of bCanEverTick inside component classes here: Unreal Engine Issues and Bug Tracker (UE-42944) . You can track the report’s status as the issue is reviewed by our development staff. Please be aware that this issue may not be prioritized or fixed soon.

Thanks for your help. I’m glad we got to the bottom of this.

I thouht I got this figured out before in earlier engine versions, but in 5.2, it seems to have changed. In C++ ctor, I have

PrimaryComponentTick.bCanEverTick          = false;
PrimaryComponentTick.bStartWithTickEnabled = false;
bAutoActivate								= true;

yet the component starts ticking. Anyone seeing same?

So I made a test and confirmed, UE4 works but not UE5. Repro here