Why can't I clear my path when going between Scenes?

For the life of me I can’t get the setpath(null) to work properly with the AILerp script. My path continues to be in place and when I enable AILerp.canMove the player goes to the previous path first before going to the new set location. Here is a snip of my code.

if (currentScene.buildIndex == 0)
{
Debug.Log(“teleporting to outside”);

            ailerp.SetPath(null);
            ailerp.destination = aiMovement.transform.position;
            aiMovement.transform.position = targetPositionEndPoint;
            //ailerp.Teleport(targetPositionEndPoint,true);
            Destroy(GameObject.Find("Highlighted_Tile(Clone)"));
        }

Is there something I am missing? From what I’ve found online using setting the path to null should remove the path.

To elaborate I need to clear/reset the path that isn’t finished because of the scene transition/teleport to a new location. I’ve been poking through the code trying to find a way to do this but when the path has been generated I don’t see anything I can do to remove it. It has to finish it’s route to the destination before my movement will proceed with a new path.

That’s odd. Have you debugged the position of aiMovement.transform.position and made sure that it is in the right place when you run that code?

I managed to get it fixed, thanks for the help! I had a piece of code somewhere else that was changing the position on me that I had forgotten about. I made a killMovement method that stops my player and clears the path. If anyone else ends up having similar issues I do this.

public void KillMovement()
{
target = new Vector3(0, 0, 0);
ai.canMove = false;
if (target != null && ai != null) ai.destination =
GameObject.FindGameObjectWithTag(“Player”).transform.position;
ai.SetPath(null);

}

1 Like