Search Unity

SetTile is too slow

Discussion in '2D' started by lethal-chicken, May 9, 2022.

  1. lethal-chicken

    lethal-chicken

    Joined:
    Jun 15, 2020
    Posts:
    1
    I have 12 total tilemaps I need to set each tile for to load a level. With smaller levels, the loading times are fine, but with larger numbers of tiles, SetTile() is just too slow. I need to be able to save and load larger tilemaps, potentially over 1000x500. So I have a couple questions about how to solve this.
    1. is there a built in way to save and load tilemaps that is faster than setting each tile individually
    2. can SetTile use multithreading and/or ECS
    This isn't a game breaking issue, it's just annoying to have to wait to load a bunch of tiles when going through a door.
     
  2. MaxwellTan

    MaxwellTan

    Unity Technologies

    Joined:
    Mar 3, 2022
    Posts:
    75
    Hi lethal-chicken, not sure I understand, maybe can give more information.
     
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    Use SetTiles or SetTilesBlock. Both of these methods are orders of magnitude faster than SetTile esp when the # grows large and if colliders are also involved.
     
    lethal-chicken likes this.
  4. vonchor

    vonchor

    Joined:
    Jun 30, 2009
    Posts:
    249
    You might also try having the tilemaps be in separate scenes, loaded additively/async. I have multiple-layer tilemaps in scenes where the maps are ~ 300*300 and use this approach. Have not benchmarked this Vs settile though.
     
  5. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    thats life

    tricks:
    - load it in advance
    - load it in coroutines so the game doesnt freeze
    - load the tiles closer to the camera first

    think about efficiency, whats the point of loading 1000 tiles deep when the camera only sees 30 tiles at once