Skip to content

Fixes panic when using Option<Gizmos>#22812

Open
kfc35 wants to merge 1 commit intobevyengine:mainfrom
kfc35:14949_gizmo_optional_system_param
Open

Fixes panic when using Option<Gizmos>#22812
kfc35 wants to merge 1 commit intobevyengine:mainfrom
kfc35:14949_gizmo_optional_system_param

Conversation

@kfc35
Copy link
Contributor

@kfc35 kfc35 commented Feb 5, 2026

Objective

Solution

Gizmos is a non #[derive]'d SystemParam that requires its

  • GizmoConfigGroup to have an entry in GizmoConfigStore
  • Various GizmoStorages to be inserted as resources.

In order to support a non-panicking Option<Gizmos> SystemParam in a non-intrusive way for users when the Gizmo Config Group has not been set up intentionally, this PR:

  • Adds ergonomic methods to get a group’s config fallibly to the GizmoConfigStore
  • Changes the validate_param method of Gizmos to return a skippable error in the event that it could not find its own config in the GizmoConfigStore
  • Changes the apply method of GizmoBuffer to only apply changes if the GizmoStorage for the config group exists.

Testing

I modified the 2d gizmos example (cargo run --example 2d_gizmos) by:

  • commenting out the init of the custom gizmo group // .init_gizmo_group::<MyRoundGizmos>()
  • Using options (i.e. Option<Gizmos> and Option<Gizmos<MyRoundGizmos>>) for the two Gizmos system parameters in draw_example_collection and requiring my_gizmos_option.is_some() before using an unwrapped my_gizmos to draw things.
  • Using the new GizmoConfigStore method try_config_mut when trying to get the config for MyRoundGizmos, and only proceeding to change its settings if my_config_option.is_some()

There are no crashes. Default Gizmos continue to be drawn, and MyRoundGizmos are not drawn. Changing the settings still works for default gizmos, and has no effect if they were to be applied to MyRoundGizmos. There seems to be no deterioration in performance for the example.

@kfc35 kfc35 added C-Bug An unexpected or incorrect behavior A-Gizmos Visual editor and debug gizmos D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward P-Crash A sudden unexpected crash A-ECS Entities, components, systems, and events labels Feb 5, 2026
@kfc35 kfc35 changed the title Adds support for Optional<Gizmos> Fixes panic when using Option<Gizmos> Feb 5, 2026
storage.list_colors.append(&mut self.list_colors);
storage.strip_positions.append(&mut self.strip_positions);
storage.strip_colors.append(&mut self.strip_colors);
if let Some(mut storage) = world.get_resource_mut::<GizmoStorage<Config, Clear>>() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self that I need to also make this change to queue() #22800

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events A-Gizmos Visual editor and debug gizmos C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples P-Crash A sudden unexpected crash S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional SystemParam (especially gizmos)

1 participant