Hello Guest

Author Topic: Saving TileMaps  (Read 3475 times)

Kalagaraz

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Saving TileMaps
« on: September 13, 2013, 06:32:46 pm »
Is there an easy way to save tile maps and reload them?

What I'm doing now is just looping through the tiles and storing the ID to an array in a scriptable object and then saving it to disk. Then loading it back and just calling SetTile() for each element etc...

It's kind of hairy though, for one I can't use GetTile() when not in play mode, so to save I have to start the game.

Just wondering if there is a better method?

Probably just be easier to start used Tiled and TMX :)
Nope...only loadable in editor. I need to be able to load them in game.

I need to be able to load lots of different ones relatively quickly.
« Last Edit: September 13, 2013, 07:03:24 pm by Kalagaraz »

Kalagaraz

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Saving TileMaps
« Reply #1 on: September 13, 2013, 08:31:31 pm »
Nevermind, got my saving and loading working pretty decently. Found out I can use Resource.Find...  to get the scene object directly and modify it. So now I can load and save maps while in the editor.

Also, not sure if it's a bug or not. But apparently GetTile and SetTile will work outside the bounds of map for a limited amount...When Loading map back I accidently swapped my mapwidth and mapheight variables and ended up writing part of the map outside the bounds and couldn't get rid of them lol.
« Last Edit: September 13, 2013, 08:34:06 pm by Kalagaraz »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Saving TileMaps
« Reply #2 on: September 13, 2013, 08:38:49 pm »
You can load stuff at runtime using SetTile, just remember to call Build once you're done. That should be all thats necessary. What you can't do at runtime is resize the tilemap, but you can just as well make it as big as you need it to be - the overhead for an empty large tilemap is nearly negligible.

Outside the bounds it might do some funny stuff before complaining - it always allocates in partition sized chunks at a time, so there might be a few more tiles available.