{"record":{"id":"73e23e9a173ca2f7","repo":"egametang/ET","slug":"duplicate-condition-variable-conditionvariableat","errorCode":null,"errorMessage":"duplicate condition variable: {conditionVariableAttribute.Variable}","messagePattern":"duplicate condition variable: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionVariableRegistry.cs","lineNumber":36,"sourceCode":"            foreach (Type type in types)\n            {\n                if (!typeof(BTCondition).IsAssignableFrom(type))\n                {\n                    throw new Exception($\"condition variable node must inherit BTCondition: {type.FullName}\");\n                }\n\n                object[] attrs = type.GetCustomAttributes(typeof(ConditionVariableAttribute), false);\n                foreach (object attr in attrs)\n                {\n                    ConditionVariableAttribute conditionVariableAttribute = (ConditionVariableAttribute)attr;\n                    if (string.IsNullOrWhiteSpace(conditionVariableAttribute.Variable))\n                    {\n                        throw new Exception($\"condition variable is empty: {type.FullName}\");\n                    }\n\n                    if (!this.variableNodeTypes.TryAdd(conditionVariableAttribute.Variable, type))\n                    {\n                        throw new Exception($\"duplicate condition variable: {conditionVariableAttribute.Variable}\");\n                    }\n                }\n            }\n        }\n\n        private void RegisterNumericTypes()\n        {\n            foreach (NumericType numericType in Enum.GetValues(typeof(NumericType)))\n            {\n                string variable = numericType.ToString();\n                this.numericTypes.Add(variable, numericType);\n                this.variableNodeTypes.Add(variable, typeof(BTNumericCompare));\n            }\n        }\n\n        public bool TryGetNodeType(string variable, out Type nodeType)\n        {\n            return this.variableNodeTypes.TryGetValue(variable, out nodeType);","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionVariableRegistry.cs#L18-L54","documentation":"Thrown during ConditionVariableRegistry.Awake() when TryAdd fails, meaning two [ConditionVariable] registrations (or a registration colliding with a built-in NumericType name) claimed the same variable string. The registry is a single Dictionary keyed by variable name, so duplicates are rejected to keep parser lookup unambiguous.","triggerScenarios":"Two node classes both declare `[ConditionVariable(\"HP\")]`; a custom variable name collides with a registered NumericType enum name (RegisterNumericTypes pre-registers each NumericType name pointing at BTNumericCompare).","commonSituations":"Renaming a node and forgetting the old one still carries the same attribute; introducing a new NumericType enum member whose name clashes with an existing custom variable.","solutions":["Rename one of the conflicting variables so each name maps to exactly one node type.","If colliding with a NumericType name, pick a different custom variable name or remove the redundant custom node.","Search the codebase for `[ConditionVariable(\"<name>\")]` and the NumericType enum to find both sources."],"exampleFix":"// before\n[ConditionVariable(\"HP\")]\npublic class CustomHpNode : BTCondition { }\n// (HP already a NumericType)\n// after\n[ConditionVariable(\"CustomHp\")]\npublic class CustomHpNode : BTCondition { }","handlingStrategy":"validation","validationCode":"// detect duplicate variable names at startup before the registry throws\nvar seen = new HashSet<string>();\nforeach (Type t in CodeTypes.Instance.GetTypes(typeof(ConditionVariableAttribute)))\n    foreach (ConditionVariableAttribute a in t.GetCustomAttributes(typeof(ConditionVariableAttribute), false))\n        if (!seen.Add(a.Variable))\n            Console.Error.WriteLine($\"duplicate condition variable: {a.Variable} on {t.FullName}\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a single canonical list of variable names and check it before adding attributes.","Remember built-in NumericType enum names are pre-registered; avoid clashing with them.","Add a duplicate-detection test run at bootstrap."],"tags":["csharp","unity","conditionexpr","attribute","bootstrap","registration"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}