Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity Update() performance

I have two functionality that need to achieve:

  1. movement
  2. rotation

both must be in Update(), i can combine it but i prefer both of them in separate script in each Movement.cs and Rotation.cs.

So i have two method:

  1. Combine both into one script in and using one Update().
  2. Separate into two script and each of them have Update().

My question : does it cost performance if separate them into each individual Update() instead of combine in one script with one Update().

Both script will be attach on one object, so if i have hundreds of object.

Method 1 - 100 objects and 100 script with Update(). Method 2 - 100 objects and 200 script with Update().

Another question : is it really bad to do Method 2 ?.

like image 246
Tengku Fathullah Avatar asked Aug 27 '26 15:08

Tengku Fathullah


1 Answers

This is a case of micro-optimisation. You should use any of the methods that makes more sense in your particular case and after you're done you should to some profiling.

Based on the results of profiling you'll end up knowing where and what to optimise.

Getting back to the problem at hand having 2 Updates will cost you one more function call per frame and some time when your MonoBehaviour is first loaded, but that is negligible, you'll eat a lot more CPU cycles in other parts of your code.

like image 167
Radu Diță Avatar answered Aug 29 '26 06:08

Radu Diță



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!