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

Which is best for performance: enable/disable Renderer or GameObject?

Discussion in 'Editor & General Support' started by kleinfb, Sep 2, 2013.

  1. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Hi guys.

    Question is simple:
    I have 2 really high-poly meshes, and I need to switch showing from one to the other....

    Which one is the best way to go? Dealing with the Renderer, or the GameObject?
    It is just a renderer based GameObject, so please, do not take into account the existence of any other components.

    Regards
     
    rf007 likes this.
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,681
    My bet would be renderer. If you are just switching the renderer on and off, Vs the entire gameObject, my bet that, will be less costly, the switch, to the engine. I would be interested in hearing more experienced opinions tho.
     
    rf007 likes this.
  3. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The Unity Profiler (if you have Pro) and System.Diagnostics Stopwatch are great tools to get those types of answers.

    Using the Stopwatch and iterating 1 million times over toggling GameObject.SetActive() between True and False took about 1335ms.

    Doing the same thing and toggling the Renderer.enabled between True and False took about 84.4ms.
     
  4. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Great to know!

    And most important, thanks for pointing out the profiler tip, I will definitely start doing that kind of testings...
     
    rf007 likes this.
  5. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    wow
     
    KiberKachok likes this.