Lightweight Locomotion?

almostchris

New member
In our project, we're using Behavior Designer, Movement Pack (NavMesh) and Ultimate Character Controller for the NPC movement and interactions. We're having serious performance issues when the overall active NPC count goes over 50. I've done all the optimizations suggested in other threads (timeStep adjustments, disabling IK and even the Animator for culled NPCs) however the main bottlenecks seem to be the Deterministic Movement and Height/Grounded checks in the Character Controller.

I'd like to use our own lightweight locomotion script for background NPCs but still be able to access the Abilities and other character controller features from Behavior Designer. Is it possible without completely butchering the existing Locomotion scripts? What would be the best approach? Thanks!
 
Can you post a picture of your profiler? If the bottleneck is within CheckGround then you can disable the vertical collisions and it'll just do a single cast to determine if the character is on the ground without readjusting. If the character is using a NavMeshAgent then the agent knows where the character can go anyway.
 
Sure here's a profiler screen with 59 active NPCs, vertical collisions enabled, timeStep at 0.02, max allowed timeStep at 0.04:
1451

I tried turning off vertical collisions, but it didn't seem to improve the performance much and the agents started going through raised platforms, which was kinda noticeable even from a distance.
Ideally, I'd like to just use the NavmeshAgent's position.y instead of collision testing, and run just enough locomotion logic to update animations and keep the npc moving at the same speed and in the same direction as the CharacterLocomotion script. I know it wouldn't be deterministic movement, but since the player would be too far away to interact with the npc or even notice, I don't think it would matter that much.
 
Can you expand CheckGround? It looks like there are some allocations as well which it shouldn't. By having the vertical collision check disabled it should be pretty minimal. The NavMeshAgentMovement doesn't update the vertical position but I like the idea of adding it.
 
1452
^This is with Vertical collisions enabled, with them disabled I get even worse performance for some reason as you can see in the screen below v1453

By the way, which script handles NavMeshAgent input? I've been going over the locomotion scripts for half the day and I couldn't find a single reference to it.
 
Thanks - it doesn't look like you are getting the allocations in that screenshot. Can you paste one where you are receiving the allocations? I'm curious where it is coming from.

The NavMeshAgentMovement ability hands the NavMeshAgent input.
 
Thanks - it looks like you are using a character that has multiple colliders? That allocation should be a one time thing as the dictionary resizes to accommodate all of the colliders.

Since you are working with a character that has multiple colliders there probably doesn't need to be a grounded check for every collider. This is useful for player-controlled characters where for example you could have the horses head on a different collider and you don't want that to go through walls. However, with an AI agent you wouldn't necessarily need this since you know which collider will always be on the ground. This optimization alone would dramatically increase the speed.
 
Holly crap, you're right, I did have two identical capsule colliders parented to my character... No idea how that happened but after removing one of them, the performance improved substantially.

1455

Thanks, Justin! And sorry for wasting your time because of my stupidity ?
 
Top