Search Unity

What happen's when gameobject.SetActive() is called ?why does it created GC when doing for complex

Discussion in 'Scripting' started by Ocean257, Jan 29, 2018.

  1. Ocean257

    Ocean257

    Joined:
    Jan 9, 2016
    Posts:
    16
    1) when the gameobject is disabled were does it stays ? the same address as it was before ?
    2) if gameobject is not active but is not seen by the camera . it won't render. but will the cpu power be used in send the mesh data to gpu ?
    if we disable such object will it send the mesh data to gpu ?
    3) also how can i know in the editor weather the mesh data is been send to the gpu ?
    4) for complex gameobject enabling and disabling the gameobject creates garbage collection why does that happens ?
     
  2. Kona

    Kona

    Joined:
    Oct 13, 2010
    Posts:
    208
    1) GameObject will always have the same ID, does not matter if it is disabled or enabled, any reference to it in other scripts won't change by disabling it.
    2) When the game object is disabled, all attached components are disabled aswell meaning that they don't do anything. Since the mesh is rendered with the Renderer component I'm quite certain it doesn't send any mesh data.
    3) -
    4) The garbage collection occur as a result of any code or objects that may cause garbage collection beeing toggled on or off. So complex objects with alot of demanding code etc. etc. can cause notable garbage collection when enabled or disabled. Eg. assigning or removing delegate/events in code cause garbage collection so if that occurs in any code of your game objects OnEnable and/or OnDisable members it will create garbage. (Just an example, there are a bazillion other things that add to the garbage collection aswell.)
     
    Ocean257 likes this.
  3. Ocean257

    Ocean257

    Joined:
    Jan 9, 2016
    Posts:
    16
    Thanks that really helped me !!
    if the gameobject is not diabled and it is not in the camera view (it won't render ) but will it send the data to GPU ?
    if yes then is there any way that i can verify this in editor ?