Search Unity

Mesh baking vs multiple game objects - how apply behaviour?

Discussion in 'General Graphics' started by wheee09, Dec 2, 2019.

  1. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    Hi all,

    For the sake of this question, assume that I'm making a chess board where I have a grid of square tiles but the dimensions of the board could be 1000x1000 or more.

    I've been looking at mesh baking and was wondering how does one apply behaviour to the tiles when they're all baked into a mesh?

    For example, for the 1000x1000 chess board, it sounds like I could render the board using prefabs then bake the resulting meshes together at runtime - behind a loading screen. At this point I wouldn't really need the 1 million game objects and can discard them.

    My question comes out of how to support the behaviour that a gameobject would normally provide. Things like hiding and showing individual tiles (ie. fog of war) or highlighting or selecting specific tiles.

    Take hiding/showing individual tiles as an example. If all of the tiles are baked into a mesh and I wanted to hide 3 or 4 tiles, would I change the mesh and the vertices directly? Or change the texture/material selectively within the mesh? With game objects, it's easy to leverage the monobehaviour and the builtin UI handling and have the game object hide/show itself.

    Are there better approaches to doing this?
     
  2. CorneliusCornbread

    CorneliusCornbread

    Joined:
    Jun 21, 2017
    Posts:
    32
    What you can do is have separate game objects for the tiles and mesh. So you bake the meshes into 1 game object and use the individual tiles without their own mesh renderers.

    If you don't want to go through that process you can use GPU instancing within the material itself.