2

In Amethyst, or numerous other game engines, there is a distinction between update for the logic and fixed_update for the rendering.

Bevy 0.4 introduced states, but there are only enter, update and exit lifecycle hooks. A custom stage can be made with constants from the stage module, but it only adds POST_UPDATE and PRE_UPDATE.

My question is in the title, but furthermore, if there is no equivalent, is there a best practice to run a system that handles the rendering?

A working solution is to make a second update system (called render for instance), my aim is however to improve performance if there is a better way to do it.

pretzelhammer
  • 13,874
  • 15
  • 47
  • 98
DSR
  • 62
  • 5

1 Answers1

3

I don't know if for your use case this is helpful but in the bevy 0.4 announcement a example that show that is possible to create a stage with FixedTimestep.

So using the example from the 0.4 announcement as a base:

use bevy::prelude::*;
use bevy::core::FixedTimestep;

fn main() {
    let target_rate = 60.0;
    App::build()
        // Add the default plugins to open a window
        .add_plugins(DefaultPlugins)
        .add_stage_after(
            stage::UPDATE,
            "fixed_update",
            SystemStage::parallel()
                // Set the stage criteria to run the system at the target 
                //  rate per seconds 
                .with_run_criteria(FixedTimestep::steps_per_second(target_rate)) 
                .with_system(my_system.system()),
        )
        .run();

}

Maybe this approach is not optimized (I don't exactly know how the FixedTimestep criteria works internally), but it should be sufficient in most of cases.

Edit


I found out that the it's possible to use the render App stages as the stage name, which should be more aligned with your needs:

use bevy::prelude::*;

fn main() {
    App::build()
        // Add the default plugins to open a window
        .add_plugins(DefaultPlugins)
        .add_system_to_stage(bevy::render::stage::RENDER, my_system.system())
        .run();

}