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

Unique Update loop per GameObject?

Discussion in 'Scripting' started by tubbz0r, Mar 25, 2016.

  1. tubbz0r

    tubbz0r

    Joined:
    May 24, 2014
    Posts:
    72
    It is possible to have multiple update loops unique per GameObject? I'm in a sitation where I need two gameobjects to operate at different speeds based on fixedDeltaTime. Not sure where to begin!
    Thanks
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Do you mean something like first GameObject is updated every frame, another one once every 3rd frame etc?
    There are various ways, you basically just have to skip execution for X frames or N seconds, that's up to you.

    If you need that for a huge number of scripts / GOs, I'd create a script that does the logic once and fires an event whenever it is ready to update. You can then just subscribe to those events, less redundant code and less 'am I ready to execute' checks.
     
  3. tubbz0r

    tubbz0r

    Joined:
    May 24, 2014
    Posts:
    72
    How would I go about skipping X amount of frames?
     
  4. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    Keep an int:frame counter and increment it
     
  5. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148