Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Approach for rendering 3D tiled based world?

Discussion in 'General Discussion' started by axvemi, Jun 23, 2022.

  1. axvemi

    axvemi

    Joined:
    Dec 3, 2021
    Posts:
    16
    Hey!

    I have been trying to solve this problem for a while, but I can't.
    I have two data classes that represent the world. One is the Grid class, which has a multidimensional array, and the other the Tile class, that represents the tile (with information about it).

    The thing is, for each tile I'm creating a GameObject that represents it (kinda like minecraft, for each position in the world it has a cube), but, the moment the world starts to have multiple gameobjects it lags or wont even load.

    A world of 500x500 meters isnt that big to play on, but its 250k of gameobjects, so I'm guessing that I'm not approaching it right.

    How should I do it?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,753
    You will need bite a problem from various points.
    1. Simplest is, reduce number of tiles.
    2. Use culling and pooling of tails.
    3. Bake terrain to single mesh.
    4. Use mesh optimization, I.e. LOD and like marching cubes.
    5. Use Draw Mesh Instancing API, to render things differently.
    6. USE DOTS (perhaps the hardest).

    Some of them may be easier than other.
    And that are only some of things, which you can do to optimise.
     
  3. axvemi

    axvemi

    Joined:
    Dec 3, 2021
    Posts:
    16
    1. Yeah, I guess thats an option, but games like Minecraft, or Dinkum are made with tiles, and are pretty big. I know minecraft uses your point 5. Don't know about the other.

    2. I need to look into that, but it won't even load when hitting play so the problem I guess it's another.

    3. The gameobjects are literally planes haha

    4. Same

    5. Hmm, I have look about it a bit, but haven't got nothing yet. I guess that I need to look more tutorials

    6. Yeah haha, maybe a bit harder, and I dont think that its the approach (But maybe an option)
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,753
  5. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    Another idea that could work and is easier to use: A particle system.
    Use the SetParticles method which is fast enough to not stutter with thousands of particles. However use a separate thread to prepare the data in the background and only add the tiles surrounding the player. That's how minecraft does it too after all - you have a limited render distance. Re-trigger like every 16 meters.
    Ideally you can have a handful of particle systems so you do not have to update everything every time.

    Also a cheap way to save a lot of rendering: Do not add tiles that are completely burried.
     
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,951
    Minecraft creates meshes representing the cubes and then renders that. Optionally with VBOs (Vertex Buffer Objects) for increased performance. We have a fairly in-depth thread on the topic that was active for 8 years.

    https://forum.unity.com/threads/after-playing-minecraft.63149/
     
    DragonCoder and Antypodish like this.
  7. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,247
    Do not use 1 GameObject per metre cube, you have to really optimise mesh rendering - you generate an optimised mesh for say every16x16 group of cubes, hidden faces are not part of the mesh. But there have been many discussions on the techniques used as above
     
    angrypenguin likes this.
  8. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,553
    Either use DrawMeshInstanced, or merge tiles together into larger meshes.

    Those games do not create a gameobject per cube.
     
  9. axvemi

    axvemi

    Joined:
    Dec 3, 2021
    Posts:
    16
  10. axvemi

    axvemi

    Joined:
    Dec 3, 2021
    Posts:
    16
    Got a lot of good ideas from there!