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

Question is it expensive to move around an object with a deep nesting of disabled objects?

Discussion in 'Scripting' started by radiantboy, Sep 29, 2023.

  1. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,592
    In my game I have one quite huge prefab, it contains all the other characters and I only turn on the one I need. Which means inside each character are 12 others (ultimately thousands of disabled gameobjects, some renderers etc), all turned off. Is this impacting performance at all? Should I somehow cull the disabled objects to improve performance? I dont think the profiler really tells you when stuff like this is a problem.

    The problem with that is that theyre pooled so it would be difficult to cull and bring things back. Im really just wondering if its an unneccessary slow down I could avoid somehow.

    Cheers guys.
    Gaz

    ps I am assuming somehow updating all the transforms would be a slow down, but I dont see why they need updating if theyre off.
     
  2. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    510
    The objects will probably still need to be checked to see if they're active or inactive.

    I suggest doing tests to see how much impact disabled objects have on performance. Instantiate a million gameObjects out of view and check your frame rate, then hit a key to disable them and check your frame rate again.

    This should give you an idea of the cost of off screen objects vs inactive objects vs the objects not existing at all.

    Let us know what happens! It'll be interesting... :)
     
    radiantboy likes this.
  3. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,592
    thanks man, that is a very good idea, I will conduct the tests. I will test 1 million in a moving object "onscreen" and "offscreen" and then one with no objects at all. Will post here, thanks again for the reply. Nice to bounce ideas my friend.