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 Should disabled objects be out of camera view?

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

  1. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,592
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,560
    Interesting thing... I'm guessing perhaps they're just thinking to get it out of all considered spatial "buckets" the game might use: rendering, occlusion, physics, nav, etc.

    I think that doing stuff like that used to be more important in older engines with less-aggressive culling.
     
    radiantboy likes this.
  3. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    510
    They don't disable the pooled gameObject. They just disable the script and move the bullet off screen.
     
    Last edited: Sep 30, 2023
  4. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,592
    Wow yeh correct, hello again :) Why do they do that then? I guess turning it on causes tons of mesh gen nonsense, so do you think pooled objects shouldnt even be off, just moved out to -9999? and no scripts? I currently turn off the object entirely (and dont move it anywhere), I wrote my own poolers assumed I was right.

    Im probably in that horrible premature optimisation phase. You know when you optimise everything to perfection, but your brain cant leave optimisation mode.... one more ms, more kb... lol im there. I remember pushing a j2me game from 1.6 meg to 60k, was exhilarating. What we need is an optimisation fairy who slaps when you have served your purpose, but it does not exist. Just squeezing it for switch.

    edit: Actually im hitting 60fps, its really just my raycasts that claim all the cpu power. Im worried about reudcing them and making AI behave different because ive tested it for hundreds of hours etc. I dont want that "fun leaking out" by changing them, so im scrabbling for more cycles. I dont think I need them, just a couple of GCs annoy me, so maybe I will look into gc controlling more, i think my entire level could run without gc.
     
    Last edited: Sep 30, 2023
  5. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,592
    ah yes thats a good point, I will do some tests see if I can find out any performance stuff. thanks you pop up all over with good answers :).
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,560
    Probably because they had a bug disabling one of their scripts (it didn't "play nice" when disabled and re-enabled) and rather than fix it they just said "We'll just move it to
    Vector3.faraway
    ..."

    For the record, I have NEVER done that, at least not in the last three days anyway.
     
    radiantboy likes this.
  7. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    510
    It seems to be an ancient script and so back in the stone age it's quite possible that when disabling a gameObject Unity would deallocate any memory and effectively destroy it. So enabling the object again would be the equivalent of instantiating it, which would defeat the whole purpose of pooling..

    I know I recall early versions of Unity would even hitch when a mesh came on screen while panning the camera around. I suspect that's because it would remove any mesh from GPU memory if it wasn't visible onscreen. Hey, GPU memory was tight back then!. :)

    And there may still be some overhead involved in enabling and disabling objects and so it's quite possible that simply moving a spent bullet out of view is still better (smoother) than disabling its gameObject.
     
    radiantboy likes this.