Simple Unity particle simulation, testing the performance of individual game objects vs drawing each particle to a single object.
To test performance, there are three Test States:
- Simulated - Simulates particles as custom classes- No gameObjects, only one Unity update loop running on the main handler. Requires gizmos to be enabled.
- As Game Objects - Simulates each particle as their own gameObject. This runs identical code, with each particle operating within their own update loop. Does not require gizmos.
- Rendered Objects - Simulates particles using the same structure as "Simulated," but attaches a simple SpriteRenderer to each one. Does not require gizmos.
Viewing the framerate through Unity's stats at runtime, I was getting the following results:
- Simulated
- Gizmos on: 280-300 fps
- Gizmos off: 470-500 fps
- As Game Objects
- Gizmos on: 240-260 fps
- Gizmos off: 350-360 fps
- Rendered Objects
- Gizmos on: 240-260 fps
- Gizmos off: 370-380 fps
Simulated with gizmos off results in no visible particles, but comparing between Game Objects and Rendered Objects, there is a slight difference. At higher magnitudes of particles, the impact will likely be much greater, but it was interesting to discover that a single particle-handler, coordinating the updates and collisions for all particles, was more efficient than each particle running their own updates.
This was meant to be the beginning of a 2D liquid simulation for a game idea, but the project ended here. There were some fun discoveries, nonetheless.
