Tilemaps

Discussion and help for Easy Save 3
Post Reply
User avatar
Jedyte
Posts: 3
Joined: Wed May 27, 2020 6:11 pm

Tilemaps

Post by Jedyte »

Hey everyone,

I'm looking for some pointers or guidance on how to save Tilemaps.

I'm aware currently Tilemap objects are not supported by ES3 (is there a technical reason for this? Or is it just not yet implemented?), so I'm trying to implement it myself. The main problems is that the tiles themselves do not load after being saved. Been struggling a while though...

Simply adding ES3UserType scripts was my first try, but does not work.

The main problem is that I don't find the actual tile data itself (e.g. pos x, y = tile 6, ... ) to serialize. Once I have that, I think it would be straightforward. I've been trying to find the data by:
  • attaching a debugger and inspecting the Tilemap objects
  • reading through the Unity YAML files for prefabs containing Tilemap objects
From the latter I noticed:

Code: Select all

--- !u!1839735485 &1702681037762649997
Tilemap:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 8758648864012842903}
  m_Enabled: 1
  m_Tiles:
  - first: {x: 0, y: -3, z: 0}
    second:
      serializedVersion: 2
      m_TileIndex: 3
      m_TileSpriteIndex: 3
      m_TileMatrixIndex: 0
      m_TileColorIndex: 0
      m_TileObjectToInstantiateIndex: 65535
      m_AllTileFlags: 1073741825
  - first: {x: 1, y: -3, z: 0}
    second:
      serializedVersion: 2
      m_TileIndex: 2
      m_TileSpriteIndex: 2
      m_TileMatrixIndex: 0
      m_TileColorIndex: 0
      m_TileObjectToInstantiateIndex: 65535
      m_AllTileFlags: 1073741825
      ...
m_Tiles is I think what I need. However, this member cannot be found for Tilemaps in scripts. I don't mean by that that is simply private, it is not there, it seems. Now this is the 1st time I try to read Unity YAML, so maybe I'm looking into the wrong class.

I would appreciate any hints of people who already succeeded in this, or even alternative approaches.

Cheers!
Jedyte

User avatar
Joel
Moodkie Staff
Posts: 2800
Joined: Wed Nov 07, 2012 10:32 pm

Re: Tilemaps

Post by Joel »

Hi Jedyte,

The fields you see beginning with 'm_' aren't accessible from the managed environment (these are only implemented in unmanaged C++). Instead, Unity provides methods such as the GetTile()/GetTileBlock() and SetTile()/SetTilesBlock() to indirectly access these variables.

There's a useful example of using GetTilesBlock here: https://gamedev.stackexchange.com/quest ... -a-tilemap

We've not added support for Tilemap at our end because it's not possible to automatically know how to serialize the Tilemap in a way which would work for all projects.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

User avatar
Jedyte
Posts: 3
Joined: Wed May 27, 2020 6:11 pm

Re: Tilemaps

Post by Jedyte »

Ah, I see. Since I saw a few "m_" fields appear in the ES3 Types window, I thought they we also present on the managed side.

Thanks for the link, Joel, I'll check it out!

Post Reply