How to stop moving (kill the path)

I cant seem to stop and kill the current path.

I did a search and it was suggested to error() the path, and set the path to null but it doesn’t work.

My unit has a path, and is walking towards it.
I call the following to kill it
seeker.GetCurrentPath ().Error ();
path = null;
The gameobject is disabled immediately after.

I reposition the unit, activate the gameobject, the old path resumes from the point it was disabled at.

If i set target to the unit’s own transform before disabling the gameobject, it sort of works.
But when I reactivate the gameobject, the object moves from old position to the repositioned position and then starts the new path.

My unit inherits AILerp.

any body have any ideas anyone?

Hi

Yeah I think there might be a bug in the current release that causes the AILerp script to not clear its path after the object has been deactivated. This has been fixed in the beta release (see https://arongranberg.com/astar/download).

The path.Error method (or perhaps more idiomatically seeker.CancelCurrentPathRequest) will only cancel the calculation of a path, it will not stop the AI from following its already calculated path.

I updated to the beta.

Same thing happens.

Object deactivated, moved location, reactivate, the object slides from old position to new position.

Odd.
Do you think you could show me the exact code that you use to do this?

public class Monster : UnitPath {
protected override void Awake () {
base.Awake ();
}

public void Init (Vector3 spawnPoint) {
	hp = 10;
	unitTarget = null;
	target = null;
	alive = true;
	myTransform.position = spawnPoint;
	Timing.RunCoroutine (_FindTarget ().CancelWith (gameObject));
}

IEnumerator<float> _FindTarget () {
	while (true) {
		yield return Timing.WaitForSeconds (1);
		if (Alive) {
			if (unitTarget == null) {
				unitTarget = FindInrangeTarget ();

				if (unitTarget != null) {
					target = unitTarget.Transform;
				}
			}
		}
	}
}

private UnitCore FindInrangeTarget () {
            // returns a unit target
	return unit;
}

public bool Alive {
	get { return alive; }
}

public void Remove () {
	target = myTransform;
	alive = false;
	//target = null;
	seeker.GetCurrentPath ().Error ();
	path = null;
}

}
There isn’t much to the code that, the only thing that the code is doing with a* is seeker.error in attempt to reset path, setting the target so unit will go to target.
UnitPath is just a copy of AILerp
I call Init to spawn the unit (different spawn point vector). The unit will find a target and go to the target.
I will call Remove() before disabling the object (pooling used)
I will call Init() again (different spawn point vector) to reactivate the object from pool.

When 2nd init is called, the unit should be at the defined spot, but it is not. It warps and then follows the path to target.

Hi

It doesn’t look like you actually deactivate the object.
Maybe you want to add gameObject.SetActive(false) in Remove and gameObject.SetActive(true) in Init.

I am deactivating the object in another class.
It is part of pooling.

Hm…

Try this:

In the AILerp script find the OnDisable method and add this line

pathSwitchInterpolationTime = float.PositiveInfinity;

I’m not completely sure if that field exists in your version (I think I renamed it at some point) but hopefully it does.

If that doesn’t work. Try to disable the ‘Interpolate Path Switches’ option if you have it enabled.