{"record":{"id":"f2380f70e7223790","repo":"egametang/ET","slug":"btenv-not-found-key-key-typeof-t-fullname","errorCode":null,"errorMessage":"btenv not found key: {key} {typeof(T).FullName}","messagePattern":"btenv not found key: (.+?) (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.behaviortree/Scripts/Model/Share/BTEnv.cs","lineNumber":87,"sourceCode":"            env.RunPath.AddRange(this.RunPath);\n            env.EntityId = this.EntityId;\n            env.TreeId = this.TreeId;\n#endif\n            return env;\n        }\n\n        public void SetTreeId(long treeId)\n        {\n#if UNITY_EDITOR\n            this.TreeId = treeId;\n#endif\n        }\n        \n        public T GetCollection<T>(string key) where T: IEnumerable\n        {\n            if (!this.dict.TryGetValue(key, out object value))\n            {\n                throw new Exception($\"btenv not found key: {key} {typeof(T).FullName}\");\n            }\n            \n            return (T)value;\n        }\n        \n        \n        public bool TryGetStruct<T>(string key, out T t) where T: struct\n        {\n            t = default;\n            if (key == null)\n            {\n                return false;\n            }\n            \n            if (!this.dict.TryGetValue(key, out object value))\n            {\n                return false;\n            }","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.behaviortree/Scripts/Model/Share/BTEnv.cs#L69-L105","documentation":"Thrown by BTEnv.GetCollection<T> when the requested key is absent from the env's internal dict. BTEnv is a typed blackboard shared across behavior-tree nodes; GetCollection retrieves an IEnumerable previously added via AddCollection. The exception surfaces both the missing key and the expected element type so you can tell which collection accessor failed.","triggerScenarios":"Calling env.GetCollection<List<long>>(\"targets\") (or any T:IEnumerable) when no AddCollection call ever wrote that key, or when the key was written under a different name/string literal.","commonSituations":"A BT node handler reads a collection that an upstream node was supposed to populate but the upstream branch never ran; a typo between the key used at AddCollection and at GetCollection; the tree was re-entered on a pooled BTEnv whose IPool.Clear wiped the dict.","solutions":["Verify the key string matches exactly between the AddCollection call and the GetCollection call (check spelling and casing).","Ensure the node that calls AddCollection runs before the node that calls GetCollection in the tree order.","Guard the read with env.ContainKey(key) before calling GetCollection, or use a default value.","If using pooled BTEnv, confirm the env was not cleared/recycled between write and read."],"exampleFix":"// before\nvar targets = env.GetCollection<List<long>>(\"targets\"); // throws [40] if never set\n\n// after\nif (env.ContainKey(\"targets\"))\n{\n    var targets = env.GetCollection<List<long>>(\"targets\");\n}","handlingStrategy":"validation","validationCode":"if (!env.ContainKey(\"targets\")) { /* return default or skip */ }\nvar targets = env.GetCollection<List<long>>(\"targets\");","typeGuard":null,"tryCatchPattern":"try { var targets = env.GetCollection<List<long>>(\"targets\"); }\ncatch (Exception e) when (e.Message.Contains(\"btenv not found key\")) { /* key absent */ }","preventionTips":["Centralize key strings as named constants shared by writer and reader nodes.","Ensure the AddCollection node runs before the GetCollection node in tree order.","Prefer ContainKey checks for optional data."],"tags":["behaviortree","btenv","key-error","csharp","unity","runtime"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}