Tested disabled Multithreading for both the RVO and the A* Pathfinding script.
Unity version: 2020.3.36f1 LTS
My setup:
One GameObject with: Pathfinder - Recast graph
One GameObject with: RVO Simulator + RVO Navmesh (Desired Simulation FPS: 5)
– Scene consists of –
World:
“2D Grid” (but placed in 3D, e.g. Y is up, not using unitys “2D style”), roughly 350x350 tiles using tilemaps. but physics / Pathfinding don’t bother with these tiles, instead they see:
One large flat quad mesh as ground
Multiple Obstacles like ocean + mountains have colliders, but made an obstacle-creator that “fills” the map with larger obstacles, so instead of 350 x 350 = 122500 colliders which are 1x1x1 cube-sized colliders, it goes down to 1050 colliders.
Agents are a bit more complicated:
They have:
Capsule collider
Rigidbody
Rich AI
Seker
RVO Controller
- child GameObject with Rigidbody + SphereCollider (used for threat-detection of units)
- if ranged units, another child with Rb + sphereColl, used for attack-range.
// Reason for having a rigidbody on childs, is because Unity group up all colliders “upwards”. So if a GameObject have multiple colliders in itself + in children. They will all start an event with scripts listening on root GameObject collider. And as I want an “AttackRange-detector-class” handle attack-range by itself. thus, needed a rigid-body on it.
So if I’m disabling using multiple threads on the pathfinder + RVO, i get a performance issue here:
RVOSimulator.Update()
…Simulator.Update()
…,Agent.CalculateVelocity() // This one cost 780ms for 60 agents
…,…Vector2.get_normalized() // called 535804 times?
…,…Agent.To2D() // called 1071608 times?
And if i use multi-threading (high-load):
RVOSimulator.Update()
…Simulator.Update()
…,Worker.WaitOne()
…,…ManualResetEventSlim.Wait()
…,…,ManualResetEventSlim.Wait()
…,…,…Monitor.Wait()
…,…,…,Monitor.Wait()
…,…,…,…Monitor.ObjWait()
…,…,…,…,Monitor.Monitor_wait() // This one have Time ms and Self ms: 3666
And I’ve followed all documentation i could find + your example-scenes as well. Tried with none, Auto Low-load & high-load threads.
Used Unitys own Navmesh + agents system before and had not close to this bad fps? And this is just the beginning of the game, have roughly 500 agents? later on a map.
Reason for changing, had some performance issue later + unity pathfinding was stupid & tried to take shortcut over impassable terrain. And read so much good reviews on this, so thought it would solve the issue.