By default, egui supports multi-pass immediate mode. This is useful for widgets like egui::Grid that need to know the size of all columns before rendering to avoid 'first-frame jitters'.
To enable multi-pass support for the primary context, use EguiPlugin::default() (which enables it by default). Your UI systems must then be added to the EguiPrimaryContextPass schedule.
Manual Context Creation
If you want to manage multiple contexts (e.g., for multiple windows or rendering to an image), you can disable automatic primary context creation via EguiGlobalSettings and assign custom schedules to additional contexts using EguiMultipassSchedule.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct SecondWindowContextPass;
fn setup_system(
mut commands: Commands,
mut egui_global_settings: ResMut<EguiGlobalSettings>,
) {
// Disable automatic creation of a primary context
egui_global_settings.auto_create_primary_context = false;
// Spawn primary window camera
commands.spawn((Camera3d::default(), PrimaryEguiContext));
// Spawn second window with its own Egui context and custom schedule
let second_window_id = commands.spawn(Window::default()).id();
commands.spawn((
EguiMultipassSchedule::new(SecondWindowContextPass),
Camera3d::default(),
Camera::default(),
RenderTarget::Window(WindowRef::Entity(second_window_id)),
));
}
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct SecondWindowContextPass;
fn setup_system(
mut commands: Commands,
mut egui_global_settings: ResMut<EguiGlobalSettings>,
) {
// Disable automatic creation of a primary context
egui_global_settings.auto_create_primary_context = false;
// Spawn primary window camera
commands.spawn((Camera3d::default(), PrimaryEguiContext));
// Spawn second window with its own Egui context and custom schedule
let second_window_id = commands.spawn(Window::default()).id();
commands.spawn((
EguiMultipassSchedule::new(SecondWindowContextPass),
Camera3d::default(),
Camera::default(),
RenderTarget::Window(WindowRef::Entity(second_window_id)),
));
}