- A* version: [5.1.2]
- Unity version: [2022.3.46f1]
When I drag an object and this object will UpdateGraph continuously, for enemies (containing seeker components) that have been spawned, the path will not change, but for enemies that have just spawned, the path will be changed.
How do I prevent my enemies from updating their paths every time they spawn?
Here is my Enemy code:
CharacterController cc;
Seeker seeker;
Path path = null;
Animator animator;
OnPathDelegate onPathComplete;
private void Start()
{
seeker = GetComponent<Seeker>();
cc = GetComponent<CharacterController>();
onPathComplete = OnPathComplete;
StartPath();
}
public void StartPath()
{
seeker.StartPath(transform.position,
LevelsController.Instance.playingLevel.basement.position,
onPathComplete);
}
void OnPathComplete(Path p)
{
if (p.error) return;
path = p;
wpIndex = 0;
}
Here is my Drag code:
public void OnDrag(Vector3 targetPos)
{
transform.position = targetPos;
bool invalid = InvalidPlacement();
UpdateGraphForAllColliders();
UpdateHighlighter(invalid);
}
void UpdateGraphForAllColliders()
{
foreach (var c in cols)
{
GraphUpdateObject guo = new(c.bounds);
AstarPath.active.UpdateGraphs(guo);
}
}