egametang/ET · error · Exception

bt node is null

Error message

bt node is null

What it means

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.

Source

Thrown at Packages/cn.etetet.behaviortree/Scripts/Model/Share/BTDispatcher.cs:60

        {
            object obj = Activator.CreateInstance(type);

            IBTHandler ibtHandler = obj as IBTHandler;
            if (ibtHandler == null)
            {
                throw new Exception($"bt handler not inherit IMActorHandler abstract class: {obj.GetType().FullName}");
            }

            Type nodeType = ibtHandler.GetNodeType();
            this.btHandlers.Add(nodeType, ibtHandler);
        }
        
        
        public int Handle(BTNode node, BTEnv env)
        {
            if (node == null)
            {
                throw new Exception($"bt node is null");
            }
            if (!this.btHandlers.TryGetValue(node.GetType(), out IBTHandler ibtHandler))
            {
                throw new Exception($"not found bt handler: {node.GetType().FullName}");
            }
            int ret = ibtHandler.Handle(node, env);
            
#if UNITY_EDITOR
            env.AddSnapshot($"Node {node.GetType().Name} {node.Id} return {ret}");
#endif
            return ret;
        }
    }
}

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Add a null check for node before calling Handle and return an appropriate default (e.g., BTResult.Failure).
  2. Trace where the null node originates — inspect the tree-building, deserialization, or traversal code.
  3. Ensure all BTNode references in the tree are assigned during construction.

Example fix

// before
int ret = BTDispatcher.Instance.Handle(node, env); // crashes if node is null

// after
if (node == null)
{
    return BTResult.Failure;
}
int ret = BTDispatcher.Instance.Handle(node, env);
Defensive patterns

Strategy: validation

Validate before calling

// Validate node is non-null before dispatching:
if (node == null)
{
    Log.Warning("BTDispatcher.Handle called with null node, skipping");
    return BTResult.Failure; // or appropriate default
}
int ret = BTDispatcher.Instance.Handle(node, env);

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/8bfd8eb0d5c34592. Report an issue: GitHub.