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

Streaming 2D Tilemaps

Discussion in 'World Building' started by LunarMountainGames, Jun 29, 2020.

  1. LunarMountainGames

    LunarMountainGames

    Joined:
    Jul 24, 2019
    Posts:
    10
    Hi all, I currenty have a working prototype of a 2d world where I'm streaming in chunks of the map from disk, deserializing them and creating them into the world at run time. Everything works except for the deserialization part slowing down the game. It's very subtle, but still noticeable. I tried breaking everything up into coroutines, treads and tasks yet I can't for the life of me, get the chunks to load without a little bit of frame drop.

    I've read a few threads on the forums stating that unity doesn't have built in support for streaming maps, and that I could consider looking at other engines, but like, for real? This isn't anything complicated. Its a single spritemap tileset with 64px tiles in a chunk of 30x30 tiles. I feel like I'm just not doing something correctly. Any help would be greatly appreciated. Thank you!
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    The first thing to do is use the Profiler as you load in a whole bunch of chunks, and see where the time is going.

    If you can spread the loading out enough, there will be no measurable glitch. For example, surely you could load just one sprite, right? But if you are using blocking file routines to read the whole file at once, or something, then that's what you need to change. The profiler should help you pin down exactly where that problem is.
     
  3. LunarMountainGames

    LunarMountainGames

    Joined:
    Jul 24, 2019
    Posts:
    10
    Okay, I'll give it a shot and see whats going on.
     
    JoeStrout likes this.
  4. LunarMountainGames

    LunarMountainGames

    Joined:
    Jul 24, 2019
    Posts:
    10
    After checking the profiler, it's a combination of my coroutine to deserialize the chunks and the update loop of the tilemap. I'm hitting a wall at this point because I don't know how to spread the loading out. I'm loading one chunk in a coroutine and using a task to help offset the load. I will have to rethink my plan here and may have to either go with having the map in memory and disabling chunks or using a different tilemap asset.
     
  5. LunarMountainGames

    LunarMountainGames

    Joined:
    Jul 24, 2019
    Posts:
    10
    Okay, I ended up consolidating my coroutines into one and using a queue to run them one at a time instead all at once and things are looking good. Thanks for suggesting to use the profiler, Joe!