Github link: GitHub - Ninjars/Cubetrastrophe at stress-test
Scene: Assets/Battleground/Gun Stress Test
I’ve been playing around with ECS and the new physics for a couple of months, pulling what I could from various sources to make a little gun turret simulation. The idea is to end up with many instances of turrets and targets for the simple spectacle of scale. I’m wanting to be able to have physically simulated projectiles, so I’ve been working on trying to support collision events, initially to spawn particle effects at the point of impact, and later to power game logic.
Having finally gotten my rotation maths working I attempted to scale the number of turrets from the 4 I was previously testing with to 100, but immediately saw skyrocketing frame times. This applies even if I remove any targets from the scene, so it’s just a bunch of turrets sitting there, waiting for something to happen.
Looking at the Profiler when running the scene containing 100 turrets, 1500ms is being taken up with NarrowPhase: ProcessBodyPairsJob
, which is basically the entire frame time. I’ve been unable to find out what that really means through docs or google, I’m assuming (given its nesting inside SimulationSystemGroup/World CollisionSystem
) that it’s a job that picks up collisions between physics colliders, though why it’s taking so long I do not know.
Looking at the Entity Debugger, it appears that CollisionSystem
I have written is taking up the majority of that time. However, disabling that script, either toggling it off in the debugger or by removing it from the project doesn’t improve frame times; instead RenderMeshSystemV2
takes on exactly the same frame time cost. I’m not sure if this is an Entity Debugger bug or what, but it’s not been very helpful for me to diagnose the issue!
So, in summary, even without anything going on the physics simulation is taking seeming exponentially longer to process with each turret I add to the scene. I may have overlooks something with how I’m creating my entities, but even then the performance impact seems unreasonably high.
Any pointers in general or in specific for investigating this and improving my lil project are most welcome!