We have a game-specific tool that silently captures the state of various systems (e.g., character collisions, procs, debug strings) every frame for N frames during simulation. Developers can toggle visibility of these states using TAutoConsoleVariable<bool> flags, which are dynamically created/destroyed based on in-game events (e.g., character spawn/death).
This approach has worked well in UE3 and UE4 across multiple projects.
In UE5, INiagaraModule::OnPostEngineInit() introduces a new behavior that listens for console variable destruction to invalidate Niagara-specific cached data. This blanket invalidation is causing issues in non-retail builds when our tool is active.
Is there a way to prevent this behavior? Or is there a hard assumption in UE5 that TAutoConsoleVariable<bool> should not be created/destroyed dynamically?
AFAIK there is no hard “assumption” like that in UE, but the intent behind cvars is definitely to create them on init and destroy them on exit, and not what you’re currently doing. That aside, that Niagara module logic is just silly, but I’m assuming you can’t change it since it sounds like you’re making a plugin of sorts.
I’d strongly suggest reworking the logic to no longer create console variables, and instead:
keep a dynamic array of flags somewhere in your module, adding and removing bools as you’re currently doing with cvars
add a console command with two parameters, where the first one identifies the bool and the second one provides a new value to set the bool to
The user syntax would change slightly; for example, let’s say it was like this before: tool.PotatoCollision true
it would simply change to something like this now: tool.set PotatoCollision true
If I’d misunderstood something lmk. I don’t see any other way to prevent Niagara from doing its thing if you can’t edit its code.
Thanks for the response. As you suggested, I would look into an alternative solution for cvars. I don’t want to modify Niagara module code to fix this issue.