{"record":{"id":"e229d9a1d04bd854","repo":"egametang/ET","slug":"condition-variable-registry-is-not-initialized","errorCode":null,"errorMessage":"condition variable registry is not initialized","messagePattern":"condition variable registry is not initialized","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionExprParser.cs","lineNumber":119,"sourceCode":"        }\n\n        private BTNode ParseCompare()\n        {\n            ConditionToken variableToken = this.Expect(ConditionTokenType.Identifier);\n            this.ReadVariable(variableToken.Text, out string ownerKey, out string variable, out bool hasOwnerKey);\n            string[] paramValues = this.ReadParams(out bool hasParams);\n            ConditionCompareOp op = this.ReadCompareOp();\n            ConditionToken valueToken = this.Expect(ConditionTokenType.Number);\n            int errorCode = this.defaultErrorCode;\n            if (this.Match(ConditionTokenType.Colon))\n            {\n                errorCode = this.ReadErrorCode();\n            }\n\n            ConditionVariableRegistry registry = ConditionVariableRegistry.Instance;\n            if (registry == null)\n            {\n                throw new Exception(\"condition variable registry is not initialized\");\n            }\n\n            if (!registry.TryGetNodeType(variable, out Type nodeType))\n            {\n                throw new Exception($\"condition variable not registered: {variable}\");\n            }\n\n            BTCondition node = Activator.CreateInstance(nodeType) as BTCondition;\n            if (node == null)\n            {\n                throw new Exception($\"condition variable node create error: {nodeType.FullName}\");\n            }\n\n            node.Id = this.NextNodeId();\n            if (node is BTNumericCompare numericCompare)\n            {\n                if (hasParams)\n                {","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionExprParser.cs#L101-L137","documentation":"Thrown by ConditionExprParser.ParseCompare when ConditionVariableRegistry.Instance is null. The registry is a Singleton populated at framework startup via its Awake (which scans ConditionVariableAttribute types). A null instance means the singleton was never created/registered, so no variables can resolve — parsing cannot proceed.","triggerScenarios":"Parsing a condition expression before the framework initialized ConditionVariableRegistry; running the parser in a context (e.g. a raw unit test or tool) that bypassed the ET singleton bootstrap; the registry was disposed/reset between bootstrap and parse.","commonSituations":"Unit tests that construct ConditionExprParser directly without bootstrapping singletons; an editor/tool process that did not run the full ET startup; ordering bug where config parsing runs before CodeTypes/Singleton initialization.","solutions":["Ensure ET framework startup (which creates and awakens ConditionVariableRegistry) completes before any condition expression is parsed.","In tests/tools, bootstrap the singleton/CodeTypes system first, or inject a mock registry.","Verify nothing disposes/resets ConditionVariableRegistry before parsing.","Check startup ordering so config import happens after singleton initialization."],"exampleFix":"// before (test parses without bootstrap)\nvar tokens = new ConditionExprLexer(\"HP > 0\").Tokenize();\nvar root = new ConditionExprParser(tokens, 0).Parse(); // throws [55]\n\n// after (bootstrap registry first)\nWorld.Instance.AddSingleton<ConditionVariableRegistry>();\n// ... then parse\nvar root = new ConditionExprParser(tokens, 0).Parse();","handlingStrategy":"validation","validationCode":"if (ConditionVariableRegistry.Instance == null) { /* bootstrap singletons before parsing */ }\n// Ensure framework startup (World.AddSingleton<ConditionVariableRegistry>()) completed first.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the full ET singleton bootstrap before parsing any condition expression.","In tests/tools, initialize CodeTypes and the registry explicitly.","Order config import after singleton initialization."],"tags":["conditionexpr","initialization","startup","singleton","csharp","unity"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}