Hi Jean,
Thanks for the reply.
There are 46 separate prefabs which represent enemies who are sitting in various places in the world. The action that is producing this latency is iterating through an array of about 5 FSMBool's checking their combined states to determine if the enemy need to start seeking the player. This action is the enemies idle state when they don't see the player and are just standing there, which is why so many of them run so frequently in the game loop.
These FSMBool's represent:
1. whether or not the enemy's line of sight of the player is occluded
2. whether or not the player is currently within a reachable part of the navigation mesh
3. whether or not the enemy is currently located in it's original spawn position or if it is standing somewhere else (to determine if it needs to find a path home to it's spawn position)
etc...
The logic which sets these flags can be very slow, so in some cases I'm using jobs to get calculate these values then storing them in the FSMBool's when they are finished calculating.
Typically iterating a small array using a for loop and checking boolean flags isn't a big deal in the game loop when the array elements are strongly typed, but in this case the unboxing seems to be causing an issue.
Since my original post, I've already reworked this so that I'm still checking these FSMBool's , but I'm short-circuiting the checks to minimize the calls to FSMBool.Value now that I know it's problematic.
The reason I'm passing at this data in FSMBool's is because my AI logic uses combinations of these flags in various actions to decide how to proceed to the next state. While I could change these flag to instead reside as class members of the enemy's C# script, it mean a large rewrite of a lot of complex logic and would be more difficult to debug as I couldn't see the value of the bools without attacking visual studio (which is very slow and cumbersome in my large project).
At any rate, my short-circuiting changes have mostly eliminated that bottleneck, so I'm on to the next issue anyway.