I had issues with the GraphUpdateScene never updating any nodes on the graph that I was currently working with, so I decided to implement the code below. This seems to produce the results I need, but this is through the use of RevertFromBackup to make sure the only nodes that are marked unwalkable are the ones currently occupied by the object. Is there an issue with using this method, or is there a better alternative available?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;
namespace FSS.BOW
{
[RequireComponent(typeof(Collider))]
public class ActivePathObstacle : MonoBehaviour
{
[SerializeField] private float m_updateRate = .1f;
[SerializeField] private float m_boundsMultiplier = 2f;
private Collider m_col;
private float m_lastTime;
private GraphUpdateObject m_guo;
private void Awake()
{
m_col = GetComponent<Collider>();
m_lastTime = Time.time;
}
private void Start()
{
Bounds bounds = m_col.bounds;
bounds.Expand(m_boundsMultiplier);
m_guo = new GraphUpdateObject(bounds);
m_guo.modifyWalkability = true;
m_guo.setWalkability = false;
m_guo.trackChangedNodes = true;
m_guo.updatePhysics = false;
}
void Update()
{
if (m_lastTime + m_updateRate <= Time.time)
{
Bounds bounds = m_col.bounds;
bounds.Expand(m_boundsMultiplier);
m_guo.bounds = bounds;
AstarPath.active.UpdateGraphs(m_guo);
m_guo.RevertFromBackup();
m_lastTime = Time.time;
}
}
}
}