#Run condition for "have I run any Commands in the previous system set"

1 messages · Page 1 of 1 (latest)

weak marlin
#

Hi,

Is there a run condition like:
"run this system if any systems in a given SystemSet ran?"

My use-case is:

  • I have a system-set where I potentially spawn/remove entities, but not 100% of the time
  • I want to run apply_deferred afterwards, but only I actually spawned-removed entities in the previous system-set, otherwise it would have performance impact by requiring exclusive world access for no reason.

Is there a built-in run condition for this or do i have to build it myself (probably using a Resource that tracks if I actually removed/added entities in the first system set)

pale topaz
#

I would question whether you actually save any performance checking first or not

#

Have you profiled this to determine if apply_deferred is blocking the world for any meaningful work?

weak marlin
#

Well running apply_deferred would remove any parallelism from my other systems because it's blocking the world, no?

pale topaz
#

Technically, yes, but it's not as easy to consider the parallelism blocked

#

What is being blocked is also important to consider

weak marlin
#

Still it probably doesn't hurt right? Are there examples of how to do this?

pale topaz
#

The kind of stuff I've done to approach this kind of question before have equally required exclusive world access and really wouldn't help

#

Requiring any sort of mutable resource to track things would break parallelism among the systems sharing it in your system set

#

An AtomicBool in an immutable resource would probably be how I would approach it, though it sounds kinda hacky

weak marlin
#

so just to be clear, there's nothing like that built in bevy?
Another approach would be to maybe have a run_condition system where I check if the Commands buffer is empty. Or does the commands buffer require exclusive world access as well?

AtomicBool sounds good

pale topaz
#

As I understand it, there is nothing built-in for this. The apply_deferred is a special-cased system that triggers the executor to apply each system's buffers, and as I understand it only the individual systems would be aware if they have unapplied commands, and only the executor would have access to those system states. Unless I'm missing some feature designed for this, I think we have to track them separately