About build withinsight and movetoward demo in runtime

Ryan Chen

New member
void Start()
{
BehaviorTree behaviorTree = gameObject.AddComponent<BehaviorTree>();
behaviorTree.StartWhenEnabled = false;

EntryTask entryTask = new EntryTask();
behaviorTree.GetBehaviorSource().EntryTask = entryTask;

Sequence rootTask = new Sequence();
behaviorTree.GetBehaviorSource().RootTask = rootTask;


WithinSight withinSight = new WithinSight();
withinSight.targetTag = "Enemy";
withinSight.target = new SharedTransform();
MoveTowards moveTowards = new MoveTowards();
moveTowards.target = withinSight.target;
rootTask.AddChild(withinSight, 0);
rootTask.AddChild(moveTowards, 1);

behaviorTree.GetBehaviorSource().HasSerialized = true;
behaviorTree.EnableBehavior();
}

This is my script, but I find when running, WithinSight will be executed and return Success, but the MoveTowards will raise an error for some low-level reason. Can you please tell me why?123.png
 

Justin

Administrator
Staff member
If you import the runtime source code from the downloads page you should be able to see the line number that is causing the problem.
 

Ryan Chen

New member
If you import the runtime source code from the downloads page you should be able to see the line number that is causing the problem.
Cool. I imported it from package manager, it seems I can't browse the source code. Anyway, this imformation is very helpful. Thanks a lot.
 
Top