diff --git a/pkg/agent/engine.go b/pkg/agent/engine.go index e04ac89..ef79915 100644 --- a/pkg/agent/engine.go +++ b/pkg/agent/engine.go @@ -107,13 +107,7 @@ func (b *Behavior) BuildEngineFromConfig(conf []byte) *Engine { } } engine.plans = cfg.Plans - core.SetSubTreeLoadFunc(func(name string) *core.BehaviorTree { - if t, ok := b.trees[name]; ok { - return loader.CreateBevTreeFromConfig(&t, b.registerMap) - } - log.Panic("create sub tree not found.") - return nil - }) + b.registerSubTreeLoadFunc() return engine } @@ -121,9 +115,20 @@ func (b *Behavior) BuildTestEngine(envs map[string]string, plan *transfer.Plan) engine := &Engine{Behavior: b} engine.envs = envs engine.plans = append(engine.plans, plan) + b.registerSubTreeLoadFunc() return engine } +func (b *Behavior) registerSubTreeLoadFunc() { + core.SetSubTreeLoadFunc(func(name string) *core.BehaviorTree { + if t, ok := b.trees[name]; ok { + return loader.CreateBevTreeFromConfig(&t, b.registerMap) + } + log.Panic("create sub tree not found.") + return nil + }) +} + type Engine struct { *Behavior plans []*transfer.Plan