Unity 2D Games Developer Question:
Download Job Interview Questions and Answers PDF
Explain me which of the following examples will run faster?
1000 GameObjects, each with a MonoBehaviour implementing the Update callback.
One GameObject with one MonoBehaviour with an Array of 1000 classes, each implementing a custom Update() callback.
Answer:
The correct answer is 2.
The Update callback is called using a C# Reflection, which is significantly slower than calling a function directly. In our example, 1000 GameObjects each with a MonoBehaviour means 1000 Reflection calls per frame.
Creating one MonoBehaviour with one Update, and using this single callback to Update a given number of elements, is a lot faster, due to the direct access to the method.
The Update callback is called using a C# Reflection, which is significantly slower than calling a function directly. In our example, 1000 GameObjects each with a MonoBehaviour means 1000 Reflection calls per frame.
Creating one MonoBehaviour with one Update, and using this single callback to Update a given number of elements, is a lot faster, due to the direct access to the method.
Download Unity 2D Games Developer Interview Questions And Answers
PDF
Previous Question | Next Question |
What is adventure? | What is root Motion? |