OnTargetReached getting called before AIPath reaches target?

I am trying to rotate an object once it reaches target. I have code inside OnTargetReached(), that will set canMove to false, so that I can set the rotation.

I noticed right away when testing though, that OnTargetReached() is being called by AIPath before the gameObject actually reached it’s destination. In other words, if I remove canMove=false from OnTargetReached(), it moves further towards the destination, before stopping.

How do I know when exactly the unity has reached it’s destination, and stopped moving? I could check movement speed each update, but that sounds inefficient. Do I need to continually check unit speed after OnTargetReached() has been called?


OnTargetReached is called when the agent is within endReachedDistance from the end of the path. You can set it to a relatively small value to make sure the agent is very close to the end of the path before it is called.

1 Like

Thank you for the reply. Setting endReachedDistance to 2 resolved it for me. Any lower and I have problems with it not even leaving it’s spawn position. I think this may be due to the large object size.