{"record":{"id":"8bfd8eb0d5c34592","repo":"egametang/ET","slug":"bt-node-is-null","errorCode":null,"errorMessage":"bt node is null","messagePattern":"bt node is null","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.behaviortree/Scripts/Model/Share/BTDispatcher.cs","lineNumber":60,"sourceCode":"        {\n            object obj = Activator.CreateInstance(type);\n\n            IBTHandler ibtHandler = obj as IBTHandler;\n            if (ibtHandler == null)\n            {\n                throw new Exception($\"bt handler not inherit IMActorHandler abstract class: {obj.GetType().FullName}\");\n            }\n\n            Type nodeType = ibtHandler.GetNodeType();\n            this.btHandlers.Add(nodeType, ibtHandler);\n        }\n        \n        \n        public int Handle(BTNode node, BTEnv env)\n        {\n            if (node == null)\n            {\n                throw new Exception($\"bt node is null\");\n            }\n            if (!this.btHandlers.TryGetValue(node.GetType(), out IBTHandler ibtHandler))\n            {\n                throw new Exception($\"not found bt handler: {node.GetType().FullName}\");\n            }\n            int ret = ibtHandler.Handle(node, env);\n            \n#if UNITY_EDITOR\n            env.AddSnapshot($\"Node {node.GetType().Name} {node.Id} return {ret}\");\n#endif\n            return ret;\n        }\n    }\n}\n","sourceCodeStart":42,"sourceCodeEnd":75,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.behaviortree/Scripts/Model/Share/BTDispatcher.cs#L42-L75","documentation":"BTDispatcher.Handle was called with a null BTNode argument. Handle is the single dispatch entry point and requires a non-null node to look up and execute the corresponding handler. A null node is a programming error in the caller — typically a tree-traversal or deserialization bug.","triggerScenarios":"Calling BTDispatcher.Instance.Handle(null, env) directly, or passing a BTNode field/reference that was never assigned (null due to missing initialization, failed deserialization, or a conditional that should have skipped dispatch).","commonSituations":"A BTNode field was never initialized in the tree. A deserialization or tree-building step produced null. A parent node's child reference is null. A conditional that should have prevented the Handle call didn't check.","solutions":["Add a null check for node before calling Handle and return an appropriate default (e.g., BTResult.Failure).","Trace where the null node originates — inspect the tree-building, deserialization, or traversal code.","Ensure all BTNode references in the tree are assigned during construction."],"exampleFix":"// before\nint ret = BTDispatcher.Instance.Handle(node, env); // crashes if node is null\n\n// after\nif (node == null)\n{\n    return BTResult.Failure;\n}\nint ret = BTDispatcher.Instance.Handle(node, env);","handlingStrategy":"validation","validationCode":"// Validate node is non-null before dispatching:\nif (node == null)\n{\n    Log.Warning(\"BTDispatcher.Handle called with null node, skipping\");\n    return BTResult.Failure; // or appropriate default\n}\nint ret = BTDispatcher.Instance.Handle(node, env);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always null-check BTNode before calling Handle.","Ensure all BTNode references are assigned during tree construction.","Trace null nodes to their origin in tree-building or deserialization code.","Return a safe default (BTResult.Failure) for null nodes rather than crashing."],"tags":["behavior-tree","null-argument","programming-error","dispatch"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}