FEnvQueryOptionInstance Generator stored in FEnvQueryInstanceCache is garbage collected

This is the second time this has showed up for me using a custom generator. The last time it happened I was able to somehow work around by making a new query from scratch.

At some point during the running of my game after multiple instances have been ran for this particular query the cached Generator is garbage collected and becomes invalid. The InstanceCache in the EnvQueryManager keeps picking up the cached instance and the query crashes when it attempts to execute on the generator.
The crash in the end crashes on the line FScopeCycleCounterUObject GeneratorScope(OptionItem.Generator); inside EnvQueryInstance.cpp.

I do have multiple versions of the query cached with different modes. The one that is crashing is returning a single result and the other functional cached instance is returning 25%.

I’m still investigating where the generator gets lost, but might either make a new query in data to attempt to work around the problem or manually look for invalid query instances in the cache and remove them.

It doesn’t appear the cache is ever reset at runtime.

I changed the tasks calling the query to return a single result and that has somehow “fixed” the garbage collection of the generator. I’ll investigate further when I get more time.

It appears this may be // FORT-16508 and thus fixed in the last commit to master for EQS. I might attemp to cherry pick the change as I cannot upgrade the engine any time soon.