Performance Experiments

I was worried about the unwieldiness of my DynObj class... the script that is attached to virtually every object that moves in the world, from buttons you can press to rocks you can pick up to giant bridges that lower into place. It's bloated to almost 400 lines to handle just about anything I want to throw at it. Each DynObj has an Update function that is constantly running, looking to chew through a queue of custom actions I have set up. And that's not to mention the physics if it's a carry-able item. If the object is sitting there, it's not much (just an if statement: if there's anything in the queue do it, if not, don't), but nevertheless I always wondered if my performance would ever slow if there are hundreds of buttons, or rocks, or whatever just sitting in my scene, waiting to be interacted with.

So I set up a test scene and a for loop and tried spawning a bunch of stuff. Here are 2000 rocks. Each of them physical, waiting to be picked up and used. No problem.

Here are colored pills falling from the sky. A hundred per second. Each one has a couple GetComponent operations on creation. Each one is told by my queue system to wait 2 seconds, turn physical and drop to the ground, change color twice, and then destroy itself after about 10 seconds. The queue is running constantly, all of them are pick-up-able items, and all of them are also checking their velocity to see if they should make a dropping sound when they hit the ground. Also no problem.

I am going to stop worrying about writing the leanest code I can possibly write and just accept that Unity is pretty efficient and this DynObj and queue system I came up with makes things a whole lot easier than last game...!

10k color-changing buttons.


Log in with to leave a comment.


I like that even your tests are aesthetically amazing. That being said, if you ever do run into performance issues, I find that judicious use of Coroutines to replace update functions works quite well.

Yes! I was thinking I would try that next. Psychologically, I just always thought of Coroutines as higher-level... fancier, luxury code. But if it saves cycles, hey...


You're not entirely wrong at that. Just make sure to use the profiler to make sure you only fancy up the stuff that matters :)


This is cool

They do look cool. Maybe I'll turn them into a puzzle down the road...