When we have many agents 50+ they start falling through the ground

I’m noticing a weird behavior in my project, everything runs fine until I have lots of agents, around 50, that’s when newly created agents, or some of the already created agents start falling through the ground, even if they are not moving at all, they would spawn and simply fall through the ground.

It’s as if there is some kind of hard limit on how many agents are supported? or could it be that some pathing calculation is taking too long (now that we have a lot of agents) and ending up being abandoned; which ends up causing the agents to just fall through the ground?

if you need information on my agents and their pathing components, it’s all here.

Does the FPS drop a lot as well?

Yea it does drop a lot. I haven’t looked at the numbers but we can notice a considerable drop.

It may be that if the fps goes low enough, the agents move forward enough in a single frame that at least half their body is below the terrain. If that happens, the agent will not be able to recover, and will fall.
You can mitigate this somewhat by ensuring that the agents are relatively tall.

I don’t think they move enough in one frame for half their body to be in the terrain. Also the terrain is flat.

This even happens to agents that simply spawn and don’t even move (and aren’t told to move either), like they spawn and just fall straight through the ground.

@aron_granberg This is still a problem :(, I tested a few things:

  • I’m able to consistently reproduce this, by spawning 24 agents at the same time, if I spawn 23 no problem, but 24 they spawn and about half of them drop through the ground a moment after they spawn (not immediately, about 1-2 seconds later). They are not told to move or anything, they simply spawn and that’s it.
  • There is a big FPS drop at the moment where the agents spawn, it only lasts for a moment and then it goes back to normal (above 30).
  • I disabled RVOController, RVOSimulator and RVODensity behavior, so the only A* components the agents have enabled are AIPath (2D, 3D) and a Seeker. (of course if I disable AIPath the problem goes away, but so does their ability to move).

I’m able to mitigate this spawning agents problem by increasing the space between them, so giving them extra space when spawning them.
If i don’t give them this extra space, i notice that right before they drop through the ground, they sorta bump into each other and turn a bit as if they’re trying to make more room for themselves.

There’s plenty of room around on the terrain, so it’s not like they ran out of room, and I don’t spawn them overlapping each other, I spawn them with a spacing of about 0.1 between them.

So for all intents and purposes the issue seems to be related to FPS drop, because even when I spawn 23 agents (the magic number from above) instead of 24, they don’t fall through the ground on spawn and they can move, but a bit later when action starts taking place and the FPS drops, some of them fall through the ground.

I can see that none of them are clipping through the terrain before they drop (also the terrain is flat), so it’s not like their bodies are halfway through the ground already before they fall.

We can take that simple scenario of just spawning 24 of them. The fact that at that moment of spawn, the FPS dips pretty hard and the agents bump into each other a bit causing a tiny movement/rotation, makes some of them fall through the ground (on a flat terrain) AFTER the FPS returned to normal; that FPS dip only lasts about 1 second or even less.

I’ll PM you a small clip of what’s happening.

That is very strange…

How tall are your agents? The yellow cylinder that the AIPath script draws. Is it reasonable?

The height is 2, it fits the agent’s model reasonably well.

I PMed you a clip, we can see the radius and height there when I enable gizmos.

any idea how I can debug this? I’m on the latest version of Unity by the way, 2022.2.8f.

update, in 4.3.77 the issue is back, again it happens when the frame rate drops considerably, but it is pretty consistent in that regard.

Reverted back to 4.3.76, where only a few agents might drop through the floor, even when the frame rate drops, it is much harder to reproduce in 4.3.76 compared to 4.3.77

Hi

Can you replicate this in any example scene?

I was able to once, it was hard, when im able to do so again i will make sure to share the project.

@aron_granberg I was finally able to pin point why this was happening, I prepared a repo project using the AStar Sample Example 2.

Basically for some reason, when we have many agents (30+) and these agents have a few trigger Sphere Colliders on them, they start falling through the ground seemingly randomly.

Obviously in my own project these trigger sphere colliders serve a purpose and they are not all on the parent game object like that, but the end result is the same.

Very strange.
I can replicate this, but I see nothing strange going on in the AIPath script.
As far as I can tell, this is a unity bug.
I can only replicate it when there are 4 sphere trigger colliders attached to each agent. These triggers shouldn’t interact with anything at all, yet they seem to have an effect.

In any case, I’d recommend using Physics.OverlapShere instead of a ton of trigger collider components, if you want to e.g. check for proximity to different objects.

If the agents don’t have the AIPath component, then they don’t fall through.

We don’t have to make the agents move (have a destination) to see the issue, even if we just hit play and give no destination to the agents, some will still fall through.

Something weird is going on for sure, but I’m afraid if I go to Unity for help they will blame the AIPath component, as without it everything is fine.

I will give the physics.OverlaySphere a try, I was using the colliders instead so I don’t have to manually manage when something gets in range, goes out of range.

Switched to using Physics.OverlapSphere and the issue is gone now. I did open a ticket with Unity, if they update me I’ll let you know :slight_smile: , thanks for your help.

1 Like

Okay got the answer, known issue, supposedly fixed in Unity 2023

1 Like