1
\$\begingroup\$

I've read an article 10000 UPDATE() CALLS. Author uses UpdateManager. It has Update method which calls Update method in all of other MonoBehaviours of objects. It works faster than calling Update method from each MonoBehaviour separately.

This Manager looks like:

private ManagedUpdateBehavior[] list;

private void Start() {
    list = GetComponents<ManagedUpdateBehavior>();
}

private void Update() {
    var count = list.Length;
    for (var i = 0; i < count; i++) {
        // UpdateMe
        list[i].UpdateMe();
    }
}

And every objects now contains component with the code:

public class ManagedUpdateBehavior : MonoBehaviour {
    // some variables

    public void UpdateMe() {
        // some logic
    }
}

It's okay if 5-6-7-8- objects will be have that component.

But what if I have 100 objects? 1000? 10000?

How to find and add all ManagedUpdateBehaviors from all objects of scene? Should I use some recursive method on On Start? Cause every object may contain other objects with the script, they may contain the other objects etc...unlimited nesting

Also some objects can be instantiating dynamically...How to add their mono to manager? What is the right way?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.