{"record":{"id":"8b938ac6d88c6392","repo":"sschmid/Entitas","slug":"unbalanced-count-with-groups-groups-length-and-group-events","errorCode":null,"errorMessage":"Unbalanced count with groups ({groups.Length}) and group events ({groupEvents.Length}).","messagePattern":"Unbalanced count with groups \\((.+?)\\) and group events \\((.+?)\\)\\.","errorType":"exception","errorClass":"CollectorException","httpStatus":null,"severity":"error","filePath":"src/Entitas/Collector/Collector.cs","lineNumber":41,"sourceCode":"        readonly GroupChanged<TEntity> _onEntityDelegate;\n\n        string _toStringCache;\n\n        /// Creates a Collector and will collect changed entities\n        /// based on the specified groupEvent.\n        public Collector(IGroup<TEntity> group, GroupEvent groupEvent) : this(new[] { group }, new[] { groupEvent }) { }\n\n        /// Creates a Collector and will collect changed entities\n        /// based on the specified groupEvents.\n        public Collector(IGroup<TEntity>[] groups, GroupEvent[] groupEvents)\n        {\n            _collectedEntities = new HashSet<TEntity>(EntityEqualityComparer<TEntity>.Comparer);\n            _groups = groups;\n            _groupEvents = groupEvents;\n\n            if (groups.Length != groupEvents.Length)\n            {\n                throw new CollectorException(\n                    $\"Unbalanced count with groups ({groups.Length}) and group events ({groupEvents.Length}).\",\n                    \"Group and GroupEvents count must be equal.\"\n                );\n            }\n\n            _onEntityDelegate = (_, entity, _, _) =>\n            {\n                if (_collectedEntities.Add(entity))\n                    entity.Retain(this);\n            };\n\n            Activate();\n        }\n\n        /// Activates the Collector and will start collecting\n        /// changed entities. Collectors are activated by default.\n        public void Activate()\n        {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/sschmid/Entitas/blob/37547d1bd280f3f1c1ef7edb44f2a206660fbfb4/src/Entitas/Collector/Collector.cs#L23-L59","documentation":"The Collector constructor requires one event matcher per group: each group must be paired with the GroupEvent (Added/Removed/AddedOrRemoved) that describes when it triggers collection. A length mismatch means the collector cannot map events onto groups and Entitas refuses to build it.","triggerScenarios":"new Collector<TEntity>(context.GetGroup(matcherA), context.GetGroup(matcherB), GroupEvent.Added) — two groups but only one GroupEvent (or vice versa); also passing groups array of length N with groupEvents of length M != N.","commonSituations":"Adding a group to a collector and forgetting to append a matching GroupEvent, or refactoring from the params single-group overload to the array overload and passing events as a single value.","solutions":["Make groupEvents.Length equal groups.Length, one GroupEvent per group","Use the params overload Collector(context.GetGroup(m), GroupEvent.Added) for a single group","Use GroupEvent.AddedOrRemoved for all groups if you don't need per-group granularity"],"exampleFix":"// before\nnew Collector<PlayerEntity>(ctx.GetGroup(Matcher.AllOf(0)), ctx.GetGroup(Matcher.AllOf(1)), GroupEvent.Added);\n// after\nnew Collector<PlayerEntity>(new[] { ctx.GetGroup(Matcher.AllOf(0)), ctx.GetGroup(Matcher.AllOf(1)) }, new[] { GroupEvent.Added, GroupEvent.Added });","handlingStrategy":"validation","validationCode":"if (groups.Length != groupEvents.Length)\n    throw new ArgumentException(\"groups and groupEvents counts must match\");","typeGuard":null,"tryCatchPattern":"try { new Collector<TEntity>(groups, groupEvents); }\ncatch (Exception e) { Debug.LogError($\"Collector config invalid: {e.Message}\"); }","preventionTips":["Keep group and event arrays side by side in the same literal","Prefer the params overload for single groups","Unit-test collector construction after changing matchers"],"tags":["entitas","collector","argument-count-mismatch"],"backgroundTag":"missing-required-argument","analyzedSha":"37547d1bd280f3f1c1ef7edb44f2a206660fbfb4","analyzedAt":"2026-09-14T00:26:23.246Z","contentChangedAt":"2026-09-14T00:26:23.246Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}