[BUG] Point & Click MoveTowards timeout and NavAgent position error

DankP3

Active member
1. UCC 2.4.5
2. Unity 2020.3.18f1 URP
3. Description:
When using nav mesh navigation on point and click, when the MoveTowards times out and the controller teleports to the destination the NavMeshAgent is left in the incorrect position and the character will continue to path to an inaccessible location
4. Steps to reproduce:
Create small test scene with area on the navmesh that is inaccessible.
Start test and click on the inaccessible area, the character will be blocked and will teleport, but will then turn and head back towards where it was when it teleported.
Note if the character is selected you will be able to see the NavMeshAgent cylinder gizmo in the Scene tab and that it is left behind.
5. The full error message (if any): N/A

Possible fixes:
Inserting this (albeit suboptimal) at the end of MoveTimeout in MoveTowards fixes it:

Code:
            var agent = GetComponent<NavMeshAgent>();
            if (agent != null) {
                agent.Warp(m_CharacterLocomotion.transform.position);
            }

Assuming this is the correct approach, it may be better to put such a method in the base PathfindingMovement ability so that it can be called in all pathfinding solutions without new references being required?
 
Good fix, and I'll make it a more generic version so it'll work with A*.
 
Top