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 a game object at a scale of x,y,z 0 (Zero) still being rendered?

Discussion in 'General Discussion' started by Kinnith7, Dec 14, 2022.

  1. Kinnith7

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    75
    I am trying to figure out some ways to optimize my space map for my multiplayer starship combat game.

    My space map would have small "zones" full of objects say a planet and some moons, maybe some destroyed ships floating in orbit, not too much stuff, then all the objects would be childed to an empty gameobject in the middle of that zone. Between these zones would of course just be empty space. The map would consist of a couple of dozen of these combat zones. I have thought about having a "universe director" object. This director would watch the zone areas in space and keep up with their distance to the player ship.

    When the player was away from a zone it would reduce its parent game object to a scale of zero. As the player approached a zone it would slowly increase its scale back to 1. I have actually tested it on a small scale and the effect was pretty good. Fine for the small game I am making.

    My question is, when a game object is reduced to a scale of zero is the game engine still trying to compute all the geometry for the object or does it just "cut off" (for lack of a better term at the moment) the object's renderer?

    Or is there just a better way to do something like this all together?
     
  2. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    706
    There is the frame debugger to check if this is the case.
    And even if it weren't rendered, I would still turn off the renderer at 0 scale.

    Just use a method or auto property to scale the objects, calling OnScaleChanged(Vector3 scale) method.
     
    angrypenguin and Kinnith7 like this.
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,323
    You need to check with frame debugger. I'd expect it to be rendered. Renderable objects provide bounds and are culled when those are outside of camera view, but I do not think there's a check to check if doubts are of size zero or not.

    To make something stop rendering, you can disable its "Renderer" component.
    You can also create comlex effects with camera stacking
     
    Kinnith7 likes this.
  4. Kinnith7

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    75
    @Gekigengar @neginfinity Thanks for the responses. I thought about just turning off the renderer in code at zero scale, just haven't implemented it yet and wondered if it might have been automatic. From your responses, I think I will implement doing it in code. I wasn't sure even if turning off the renderer component actually affected that, but I suppose it controls rendering the mesh. Thanks for the help
     
  5. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    855
    They will be rendered if they are 3d objects (3d meshes) but if they are UI elements, the story is different. If the scale x or y is zero, they will probably not be rendered,
     
    Kinnith7 likes this.
  6. Kinnith7

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    75
    thanks for the info. I appreciate it. :)
     
  7. Kinnith7

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    75
    @thaheemking121 Thanks. I am going to try some things in the way of occlusion culling. I think that will work best.
     
  8. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,509
    It's possible for a shader to move vertices or even generate new ones after the mesh has been transformed in the scene, so Unity can't safely assume that all zero scaled objects are invisible.
     
    NotaNaN, Ryiah and DragonCoder like this.
  9. Kinnith7

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    75
    @angrypenguin Thanks, I think using occlusion culling or just some code of my own that shuts off the renderers would work best. I'm also looking at some Game Optimizer assets in the Unity Asset Store. I appreciate everyone's help.