Skip to content

Commit

Permalink
Fixed bug: agent sometimes not detecting parent change because when t…
Browse files Browse the repository at this point in the history
…he transform.parent was the root scene, the savedParent had the same null value as when it is was uninitialized
  • Loading branch information
jadvrodrigues committed Nov 26, 2020
1 parent 3a20747 commit 091b4eb
Show file tree
Hide file tree
Showing 2 changed files with 2,383 additions and 2,366 deletions.
21 changes: 4 additions & 17 deletions Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,21 +334,6 @@ NavMeshAgent NavMeshAgent
}

Transform savedParent;
Transform SavedParent
{
get
{
if (savedParent == null)
{
savedParent = transform.parent;
}
return savedParent;
}
set
{
savedParent = value;
}
}

Vector3? savedPosition;
Vector3? SavedPosition
Expand Down Expand Up @@ -485,9 +470,9 @@ public void RecordNavMeshAgent()
onPositionChange?.Invoke();
}

if (SavedParent != transform.parent)
if (savedParent != transform.parent)
{
SavedParent = transform.parent;
savedParent = transform.parent;
onParentChange?.Invoke();
}

Expand Down Expand Up @@ -520,6 +505,8 @@ protected override void OnCustomEnable()
NavMeshAgent.enabled = true;

TryCreatingHiddenAgent();

savedParent = transform.parent;
}

protected override void OnCustomDisable()
Expand Down
Loading

0 comments on commit 091b4eb

Please sign in to comment.