Has anyone found a good solution when using a large amount of navmesh agents? I found a threading script recently that has improved performance by a decent amount but still if I hit around 50 agents I get a large delay for calculating agent movement. Is there a way to improve this code to handle large amounts of agents using SetDestination()?
using System.Threading;
using UnityEngine;
public class ThreadedBehaviour : MonoBehaviour
{
Thread ChildThread = null;
EventWaitHandle ChildThreadWait = new EventWaitHandle(true, EventResetMode.ManualReset);
EventWaitHandle MainThreadWait = new EventWaitHandle(true, EventResetMode.ManualReset);
void ChildThreadLoop()
{
ChildThreadWait.Reset();
ChildThreadWait.WaitOne();
while (true)
{
ChildThreadWait.Reset();
// Do Update
WaitHandle.SignalAndWait(MainThreadWait, ChildThreadWait);
}
}
void Awake()
{
ChildThread = new Thread(ChildThreadLoop);
ChildThread.Start();
}
void Update()
{
MainThreadWait.WaitOne();
MainThreadWait.Reset();
ChildThreadWait.Set();
}