Search Unity

Question Building floor with different materials

Discussion in 'World Building' started by Namysoft, Feb 21, 2023.

  1. Namysoft

    Namysoft

    Joined:
    Sep 8, 2018
    Posts:
    10
    Hey guys,

    i have a grid system implemented in my game where a grid-cell represents one piece of the grid.
    Now i want to build a floor on every cell like in project hospital:



    Some fields could be a wood floor, some could be a carpet,

    I can instantiate a plane for every cell and edit the material on it and it works fine with a 50x50 grid. (every plane is static, cast now shadows [because of performance])

    But if i try to create a grid with 300x300 i got some fps drop because there are too many objects to render.

    What i tried:
    - Create a gameobject for every cell (Performance-Settings: static, cast Shadows off)
    - I played around with shaders but with my solution it wasnt possible to create complex results.
    - I created 1 gameobject with mesh for my whole grid with x submeshes (one submesh for each cell). In unity its now possible to add a material on the meshrenderer-component for each submesh. with a 100x100 there was 10.000 submeshes with 10.000 materials on 1 gameobject. Suprise: Unity breaks

    Do you have any better idea to do something like this?
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,055
    How many different materials can you have?
    You can just use a handful of materials and assign them. Then Unity can batch them together woth SRP batching or dynamic batching.
    You can also use texture atlassing to batch even more
     
  3. Namysoft

    Namysoft

    Joined:
    Sep 8, 2018
    Posts:
    10
    So you mean i have to use many gameobjects (one fpr every grid cell?) or just one gameobject.
    I think every cell can have up to 15-20 different material options (but only one is active)
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,055
    It's not about gameobjects. It's about the meshes and amount of draw calls it generates.
    You can also manually use static batching via c# depending on your use case, but dynamic batching probably already is enough
     
  5. Namysoft

    Namysoft

    Joined:
    Sep 8, 2018
    Posts:
    10
    if i set every gameobject to static batching, i still drop from 500 fps to 200. and if i increase the amount of grids up to 100x100 i drop down to 30 fps.
     
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,055
    Maybe try dynamic batching or if you use URP/HDRP SRP batching
     
  7. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,023
  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,428
    could also check unity Tilemap, or SuperTilemap from asset store,
    or other tilemap plugins..