So, I’ve got a move node set with Move Target = moveTarget. ‘moveTarget’ is a variable set in a script:
protected GameObject moveTarget;
public GameObject MoveTarget
{
get{ return moveTarget;}
set
{
moveTarget = value;
aiRig.AI.WorkingMemory.SetItem<GameObject>("moveTarget", moveTarget);
}
}
The Unity objects can have various behavior, seeking, avoidance, following waypoint routes, etc.
When they first start up, if they don’t detect or have a target, they sit still (The Move node does not execute), which is fine. I note that in the AI memory, “moveTarget” does not exist. This is desired behavior.
In my custom detection, I try to detect objects. If an object is found and is a valid target, “moveTarget” is set to that gameObject. Otherwise: “moveTarget” is set to null.
Unfortunately, as soon as “moveTarget” is set to null, the object takes off headed for (0,0,0). In looking at the assembly browser for MoveAction, I see it does:
if (this.moveTarget != null && this.moveTarget.IsValid)
...etc
I would expect that this would prevent anything from happening if moveTarget was null. However, the local variable moveTarget is:
public MoveLookTarget moveTarget = new MoveLookTarget();
… and it seems to be using that if the ai memory variable assigned to the behavior tree ‘MoveTarget’ exists, but is null. This seems like a bit of a bug.
Once I realized this it is pretty easy to get around:
if (moveTarget != null)
aiRig.AI.WorkingMemory.SetItem<GameObject>("moveTarget", moveTarget);
else
aiRig.AI.WorkingMemory.RemoveItem("moveTarget");
..but that is a bit of a hack. I doubt this is the intended behavior, so I thought I’d point this out.