Closed
Description
If I spawn a NodeComponent bundle from a system running in the POST_UPDATE stage I get a panic on this line: https://github.com/bevyengine/bevy/blob/master/crates/bevy_ui/src/flex/mod.rs#L135
The same system running in UPDATE doesn't trigger a panic. In this example, changing line 6 to add_system(node_adder.system())
makes the panic disappear.
use bevy::prelude::*;
fn main() {
App::build()
.add_default_plugins()
.add_system_to_stage(stage::POST_UPDATE, node_adder.system())
.add_resource(DidSpawn(false))
.add_startup_system(setup.system())
.run();
}
struct DidSpawn(bool);
fn setup(
mut commands: Commands,
) {
commands
.spawn(UiCameraComponents::default());
}
fn node_adder(
mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,
mut did_spawn: ResMut<DidSpawn>,
) {
if !did_spawn.0 {
did_spawn.0 = true;
commands
.spawn(NodeComponents {
style: Style {
size: Size::new(Val::Px(200.0), Val::Percent(100.0)),
border: Rect::all(Val::Px(2.0)),
..Default::default()
},
material: materials.add(Color::rgb(0.65, 0.65, 0.65).into()),
..Default::default()
});
}
}