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 How to build a big level as one game object?

Discussion in 'World Building' started by babaliaris, Dec 17, 2020.

  1. babaliaris

    babaliaris

    Joined:
    Apr 21, 2013
    Posts:
    34
    The title might seem a bit weird but this is what I'm trying to achieve:

    I want to build an FPS game with quite a lot of enemies moving around and in order to do so I want to reduce the number of static non-interactive objects that my Level is consist of as low as possible, so I can have more room to add moving objects without overloading the CPU.

    First, I thought of designing my level in Blender and then importing it as a single model inside my game. The problem is that Unity creates a hierarchy of objects, I believe for each mesh of the model. So this does not solve my problem.

    Then, I thought of exporting my level as a huge single mesh. I believe this will work but might introduce another problem that relates to the GPU. I believe if the mesh data are too much, then they will occupy too much Vram. Is this correct?

    Can I achieve that? Is there a better way to do what I'm looking for?

    For example, if my Level consists of 10,000 meshes, then do I need to worry about game objects overoalding? Because Unity is going to create a tree of 10,000 game objects if I'm right.

    Thank you!
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    This is a misconception. The whole point of static objects is that they can be statically batched, i.e., combined together automatically and submitted as a single draw call. (And it's the GPU you should be worried about overloading, not the CPU by the way.)

    Static objects will be batched as long as they share the same material. So all you need to worry about, as a level designer, is making the whole level in one material (or as few materials as you can).
     
    babaliaris likes this.
  3. babaliaris

    babaliaris

    Joined:
    Apr 21, 2013
    Posts:
    34
    Thank you for your reply!

    I'm not worried about the rendering though... If I understood correctly, you're talking about increasing FPS by using batch rendering, so the whole level would be drawn in the least possible draw calls.

    What I care about are the actual game objects that Unity has to go through each frame to run the component's functionality.

    I don't know how Unity is implemented, but I guess if I have 10,000 game objects into the scene then, Unity has to "for" loop them all. Isn't this why if I create 10,000 cubes in one scene, then the game starts to lag a lot? Or is it because of the box colliders? This is basically what I'm trying to solve. If I have the least amount of game objects in my scene, then I have more space to use for enemies until fps starts dropping.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    No. If there's some component on each of them with an Update or LateUpdate method, then yes. Otherwise, no.

    It's the rendering, plus the box colliders. (Want to see the balance between these two? Turn off one or the other, and see how the frame rate changes.)

    Not really, no. There is a little overhead to game objects when you get up into the thousands, but it's minimal.
     
    babaliaris likes this.
  5. babaliaris

    babaliaris

    Joined:
    Apr 21, 2013
    Posts:
    34
    Thank you for your answers! I'm not very knowledgeable of game engines this is why I'm struggling to understand what it's going on :p

    I find it weird, why my GPU can't draw 10,000 cubes. It should be easy since 1 cube = 36 verts * 10,000 = 360,000 verts in total. My GPU can play games like GTA V with high graphics. So why when using Unity I can't render 10,000 simple cubes? It seems weird.
     
  6. babaliaris

    babaliaris

    Joined:
    Apr 21, 2013
    Posts:
    34
    I tried rendering 8,000 cubes by instantiating them as actual game objects and I had 35FPS. Then I removed the box collider from the prefab, tried again, and barely see any difference in performance. So the problem is not the box collider for sure. Also, the cubes were being instantiated from the same prefab which means they had the same material, so unity should have batch render them.

    So I can't understand, why is the GPU straggling so much to draw 8,000 cubes...
     
  7. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    760
    babaliaris likes this.
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    Only if they are Static. Which they can't be if they were instantiated from code at runtime.

    EDIT: See this for yourself with https://docs.unity3d.com/Manual/Profiler.html
     
    babaliaris likes this.