{"record":{"id":"297bb6ff60aae264","repo":"bevyengine/bevy","slug":"tried-to-order-against-0-in-a-schedule-that","errorCode":null,"errorMessage":"Tried to order against `{0:?}` in a schedule that has more than one `{0:?}` instance. `{0:?}` is a `SystemTypeSet` and cannot be used for ordering if ambiguous. Use a different set without this restriction.","messagePattern":"Tried to order against `(.+?)` in a schedule that has more than one `(.+?)` instance\\. `(.+?)` is a `SystemTypeSet` and cannot be used for ordering if ambiguous\\. Use a different set without this restriction\\.","errorType":"exception","errorClass":"SystemTypeSetAmbiguityError","httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/src/schedule/node.rs","lineNumber":909,"sourceCode":"}\n\nimpl Index<SystemSetKey> for SystemSets {\n    type Output = dyn SystemSet;\n\n    #[track_caller]\n    fn index(&self, key: SystemSetKey) -> &Self::Output {\n        self.get(key).unwrap_or_else(|| {\n            panic!(\n                \"System set with key {:?} does not exist in the schedule\",\n                key\n            )\n        })\n    }\n}\n\n/// Error returned when calling [`SystemSets::check_type_set_ambiguity`].\n#[derive(Error, Debug)]\n#[error(\"Tried to order against `{0:?}` in a schedule that has more than one `{0:?}` instance. `{0:?}` is a `SystemTypeSet` and cannot be used for ordering if ambiguous. Use a different set without this restriction.\")]\npub struct SystemTypeSetAmbiguityError(pub SystemSetKey);\n\n#[cfg(test)]\nmod tests {\n    use alloc::{boxed::Box, vec};\n\n    use crate::{\n        prelude::SystemSet,\n        schedule::{SystemSets, Systems},\n        system::IntoSystem,\n        world::World,\n    };\n\n    #[derive(SystemSet, Clone, Copy, PartialEq, Eq, Debug, Hash)]\n    pub struct TestSet;\n\n    #[test]\n    fn systems() {","sourceCodeStart":891,"sourceCodeEnd":927,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/src/schedule/node.rs#L891-L927","documentation":"Ordering against a system by type (.before(fn_name) etc., where the function becomes a SystemTypeSet matched by type, not instance) is only permitted when the schedule holds at most one system of that type. SystemSets::check_type_set_ambiguity found more than one instance, so the constraint cannot be resolved to a single target. Returned as part of ScheduleBuildError during schedule initialization.","triggerScenarios":"Calling .before(f)/.after(f) when the function f was added more than once to the same schedule (duplicate add_systems registration, added by a plugin and again manually, or registered by a generic helper twice); the ambiguity is detected while the schedule builds.","commonSituations":"A plugin registers a system and user code adds it again; parameterized registration helpers that add the same function under multiple conditions; refactoring one system into several instances while old type-based ordering constraints remain.","solutions":["Order against a named SystemSet instead: put the target system(s) in MySet and use .before(MySet)/.after(MySet).","Deduplicate the registration so the function exists once in that schedule.","If multiple instances are intentional, give each a distinct set or wrapper and order against those."],"exampleFix":"// before\napp.add_systems(Update, (spawn_wave, spawn_wave.run_if(in_boss)));\napp.add_systems(Update, hud.before(spawn_wave)); // which spawn_wave?\n\n// after\napp.add_systems(Update, (spawn_wave, spawn_wave.run_if(in_boss)).in_set(SpawnSet));\napp.add_systems(Update, hud.before(SpawnSet));","handlingStrategy":"try-catch","validationCode":"// After all systems are registered, assert the type is unique before first run\nlet count = schedule\n    .systems()?\n    .filter(|(_, s)| s.name().ends_with(\"spawn_wave\"))\n    .count();\nassert!(count <= 1, \"system type used for ordering is duplicated\");","typeGuard":null,"tryCatchPattern":"match schedule.initialize(&mut world) {\n    Ok(()) => {}\n    Err(e) if mentions_type_set_ambiguity(&e) => {\n        // switch the constraint to a named SystemSet and rebuild\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Order against named SystemSets instead of bare function names whenever duplication is possible.","Keep a single registration point per system; guard against plugins double-registering.","Add a smoke test that initializes each schedule once."],"tags":["bevy","ecs","schedule","system-ordering","ambiguity","system-set"],"backgroundTag":"ambiguous-identifier-resolution","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}