{"record":{"id":"1d629277cd095e74","repo":"bevyengine/bevy","slug":"setshaveorderbutintersect","errorCode":"SetsHaveOrderButIntersect","errorMessage":"`{:?}` and `{:?}` have a `before`-`after` relationship (which may be transitive) but share systems.","messagePattern":"`(.+?)` and `(.+?)` have a `before`-`after` relationship \\(which may be transitive\\) but share systems\\.","errorType":"error_code","errorClass":"ScheduleBuildError","httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/src/schedule/error.rs","lineNumber":36,"sourceCode":"\n/// Category of errors encountered during [`Schedule::initialize`](crate::schedule::Schedule::initialize).\n#[non_exhaustive]\n#[derive(Error, Debug)]\npub enum ScheduleBuildError {\n    /// Tried to topologically sort the hierarchy of system sets.\n    #[error(\"Failed to topologically sort the hierarchy of system sets: {0}\")]\n    HierarchySort(DiGraphToposortError<NodeId>),\n    /// Tried to topologically sort the dependency graph.\n    #[error(\"Failed to topologically sort the dependency graph: {0}\")]\n    DependencySort(DiGraphToposortError<NodeId>),\n    /// Tried to topologically sort the flattened dependency graph.\n    #[error(\"Failed to topologically sort the flattened dependency graph: {0}\")]\n    FlatDependencySort(DiGraphToposortError<SystemKey>),\n    /// Tried to order a system (set) relative to a system set it belongs to.\n    #[error(\"`{:?}` and `{:?}` have both `in_set` and `before`-`after` relationships (these might be transitive). This combination is unsolvable as a system cannot run before or after a set it belongs to.\", .0.0, .0.1)]\n    CrossDependency(#[from] DagCrossDependencyError<NodeId>),\n    /// Tried to order system sets that share systems.\n    #[error(\"`{:?}` and `{:?}` have a `before`-`after` relationship (which may be transitive) but share systems.\", .0.0, .0.1)]\n    SetsHaveOrderButIntersect(#[from] DagOverlappingGroupError<SystemSetKey>),\n    /// Tried to order a system (set) relative to all instances of some system function.\n    #[error(transparent)]\n    SystemTypeSetAmbiguity(#[from] SystemTypeSetAmbiguityError),\n    /// Tried to run a schedule before all of its systems have been initialized.\n    #[error(\"Tried to run a schedule before all of its systems have been initialized.\")]\n    Uninitialized,\n    /// A warning that was elevated to an error.\n    #[error(transparent)]\n    Elevated(#[from] ScheduleBuildWarning),\n}\n\n/// Category of warnings encountered during [`Schedule::initialize`](crate::schedule::Schedule::initialize).\n#[non_exhaustive]\n#[derive(Error, Debug)]\npub enum ScheduleBuildWarning {\n    /// The hierarchy of system sets contains redundant edges.\n    ///","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/src/schedule/error.rs#L18-L54","documentation":"`SetsHaveOrderButIntersect` fires when two system sets have a `before`/`after` relationship but share at least one system. The shared member would need to run both before and after itself relative to the sets' orderings, which is impossible, so schedule initialization fails with the two set keys named.","triggerScenarios":"`.configure_sets(Update, A.before(B))` while some system is registered `.in_set(A).in_set(B)`; sets defined by disjoint concerns that accidentally share a member; base-set abstractions (e.g. a 'Everything' set) ordered against a specific set it contains members of.","commonSituations":"Cross-cutting sets (debug, networking) that collect systems also owned by phase sets, then get ordered against them; plugin composition where each plugin adds its systems to both a shared set and a local one that is later ordered; refactors introducing a second membership without checking ordering.","solutions":["Remove the shared membership — keep each system in exactly one of the two ordered sets","Or drop the ordering between the intersecting sets (order their non-shared members directly)","If the overlap is intentional, model the shared systems as a third set and order the sets without intersection"],"exampleFix":"// before\napp.configure_sets(Update, AiSet.before(PhysicsSet));\napp.add_systems(Update, steering.in_set(AiSet).in_set(PhysicsSet)); // intersection\n\n// after\napp.add_systems(Update, steering.in_set(AiSet));","handlingStrategy":"try-catch","validationCode":"// Maintain membership counts per set in your config; before ordering A vs B, assert:\nassert!(shared_members(&set_a, &set_b).is_empty(), \"ordered sets must not intersect\");","typeGuard":null,"tryCatchPattern":"match schedule.initialize(&mut world) {\n    Err(ScheduleBuildError::SetsHaveOrderButIntersect(DagOverlappingGroupError(a, b))) => {\n        // a and b share systems: drop the ordering or the shared membership\n    }\n    other => other.map(|_| ()),\n}","preventionTips":["One ordering-relevant membership per system; use tags/disjoint sets for grouping","Avoid ordering broad cross-cutting sets against specific ones","When adding a second .in_set to a system, check whether the two sets are ordered relative to each other"],"tags":["bevy","ecs","schedule","system-sets","ordering"],"backgroundTag":"conflicting-ordering-constraints","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}