Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Feedback Merging all Updates into 1

Discussion in 'Scripting' started by ricardoCoelho, Nov 23, 2020.

  1. ricardoCoelho

    ricardoCoelho

    Joined:
    Jul 6, 2020
    Posts:
    18
    Hi guys,
    In one of the projects I'm working on, we decided to merge multiple Updates into just one.
    We have the objects in the Start add themselves to a list of objects and then the MasterObject runs through this list every frame and runs a custom Update method in each class.
    Code (CSharp):
    1. class SmallClass
    2. {
    3.   Start()
    4.   {
    5.     MainClass.ListClasses.Add(this);
    6.   }
    7.   CustomUpdate()
    8.   {
    9.     //do stuff
    10.   }
    11. }
    12.  
    13. class MainClass()
    14. {
    15.   list<SmallClass> ListClasses;
    16.   Update()
    17.   {
    18.     Foreach(SmallClass aux in ListClasses)
    19.       aux.CustomUpdate();
    20.   }
    21. }
    On a second project I believe this does not make as much sense as it did in the first project but my teammate is sugesting this second project should follow the pattern for patterns sake.
    Does this make sense? Should we apply this same principle on the second project because its written in our guidelines that we made for our first project?
    Even if we didn't have single Update this applied in a project, does this make sense to make?
    I'm finding myself questioning the first implementation now that I'm questing the second as well.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    What is the reason for doing it this way? All I can think of is so you can more easily control the order they are called. I doubt you see any performance benefit.

    What I'm getting at, is if you have a good reason doing this improves your development or improves performance, then keep doing it. If not, then I wouldn't.
     
  3. ricardoCoelho

    ricardoCoelho

    Joined:
    Jul 6, 2020
    Posts:
    18
    On the first project it makes sense because we have a ton of big and tiny objects, and sometimes we had alot of them running Update when they shouldn't because we couldn't control that. By adding them to a list and running update from that, we regained control of that Update call.