Search Unity

Performance advice requested, need to move thousands of individual objects.

Discussion in 'Editor & General Support' started by fransh, Nov 9, 2013.

  1. fransh

    fransh

    Joined:
    Sep 15, 2010
    Posts:
    92
    Hey all.

    I got this project running where i require to move a lot of objects constantly. These objects move towards a target at all times, target differs per objects. I am not talking hundred of objects, i am moving thousands of them, so any bit of performance i can get extra would give quite a bit seeing the number of objects.

    One thing i did to start with, it to make all objects be moved from one script. Going trough one array containing all units and telling them all to move. When comparing this to giving each object their own Update, and making them move on their own gives no performance increase at all, it is infact the same. This suprised me a bit because the amount of Update calls are reduced dramaticaly, is there anything else i can do to boost this?

    Also these objects need to move, so i am simply using transform.Translate to move them from their current position, to the position they need to go to. Ofcourse everything i can cash is cashed, but is there a more performance friendly way of doing what Translate() does?

    I am not that unhappy with the current performance, but since i can not think of any good alternatives, than that most likely means there is stuff i do not know. So if anyone got a idea on how i could get some extra performance out of that, i would be gratefull.
     
  2. Roland1234

    Roland1234

    Joined:
    Nov 21, 2012
    Posts:
    190
    I don't know of any way of modifying a ton of object positions that would be more effective than what you're already doing by iterating through them and modifying their transform - any way I know of modifying their transform I think comes down to the same (or very similar thing) so calling Translate() vs. ... something else... I don't think would make a difference.

    The only thing I would suggest would be to limit the frequency of these updates. You could easily write in a delay that only updates the object transforms every x milliseconds or number of frames, or simply modify the Fixed Timestep value if you are updating them on the FixedUpdate method.

    I would try to split the large set of objects into smaller sets that get updated alternatively throughout an evenly distributed amount of time - so you'd end up with, I dunno, 10 sets of objects with ~500 objects each and every 10ms or something you move to the next set, updated their positions, then wait another 10ms, and so on and so forth...?

    Yeah, something like that.