#Saving TileSet in code results in corrupted TileMapLayer? (and unclear documentation)

1 messages · Page 1 of 1 (latest)

lost cloud
#
  1. Running the TileSet generation code creates a TileSet resource and I am able to also assign Tiles from to a TileMapLayer in code (not doing this in the GUI yet)

  2. When I open the generated TileMapLayer Scene in the GUI the TileSet tile that I assigned to the TileMapLayer coords are corrupt (missing?)

  3. In the GUI, when I open the TileSet corresponding to the TileMapLayer, the tiles are all **greyed out **(image shared)

  4. Only when I click on the individual tile in the atlas/texture window does it THEN get recognized in the TileMapLayer

What is happening here? I have a feeling it is maybe related to the errors I also have posted. But it's concerning that the errors don't prevent the TileSet from being created in the first place.

https://docs.godotengine.org/ja/4.x/classes/class_tilesetatlassource.html#class-tilesetatlassource-property-texture-region-size
^^if the units of a texture_region_size are in pixels (incorrect assumption?), then why would a texture_region_size have to differ from the TileSet's tile_size?

Updating the atlas_source.set_texture_region_size(Vector2i(16, 16)) to an 18x18 texture_region_size, also causes more issues, like the tiles no longer being selectable/un-greyed-out (in the GUI).

With no CLEAR explanation as to why this relationship between TileSetAtlasSource.texture_region_size and TileSet.tile_size exists, i feel like the documentation needs to be improved to articulate this better somehow, and perhaps provide code examples as well

thin flicker
#

I believe texture_region_size is in pixels and tile_size is in grid tiles.

#

So you would want (16, 16) and (1, 1) respectively.

lost cloud
#

for reference to how im filling the TileMapLayer (the INTACT enum is just index 1 in the texture atlas (i.e. the 16x16 white tile)

thin flicker
#

I just checked my tileset, both the tile set size and atlas source region size are (16, 16)

#

I set it up through the GUI not through code but I don't think that should change anything.

#

I think the docs might be incorrect stating that region size must be bigger. I assume it is probably >=

lost cloud
thin flicker
lost cloud
thin flicker
#

In the original code you posted you are calling create_tile with a size of (1, 1)

lost cloud
# thin flicker In the original code you posted you are calling `create_tile` with a size of (1,...

Right, that's the create_tile that takes in grid size, the 'set_tile_size' is called at the bottom with 16

Please check the docs: https://docs.godotengine.org/en/stable/classes/class_tilesetatlassource.html#class-tilesetatlassource-method-create-tile

thin flicker
#

I believe the size that is being passed into create_tile is the TileSetAtlasSource.texture_region_size which should be (16, 16).

#

On my own tilemap layer I logged out these sizes.

    Log.info("tileset size: %s, tilesetatlassource: %s" % [
        current_level_tilemaplayer.tile_set.tile_size,
        (current_level_tilemaplayer.tile_set.get_source(0) as TileSetAtlasSource).texture_region_size,
    ])

Main/INFO [16:44:13] tileset size: (16, 16), tilesetatlassource: (16, 16)

thin flicker
lost cloud
#

So I moved the set_tile_size to the top before the create_tile, and then grab the tile_size itself just in case.... but still...

#

what's even more confusing though is that yes its erroring at the create_tile() method, but it seems to still be passing out to the bottom of the function enough to generate the tileset (it gets saved with the expected sizes as i expect)

It still has the same result as in the original post...

thin flicker
#

If you put some breakpoints in there and step through the execution is everything what you expect?

lost cloud
#

Yes, but its the same behavior as the original posts screenshots, the only difference being that the tile_size is incorrectly set to (1,1) in the create_tile function (but actually this doesnt cause any issues, because i correct for it outside of the loop with set_tile_size it seems).

The TileSet gets created, but its something hidden in that i cant get breakpoints at the level where this issue which is related to the "greyed-out" tileset tile behavior can be pinpointed

#

im trying to avoid having to dig into the c++ is all

#

because this behavior is not documented from what i can tell...

#

do you know what it is called when you "click" on a tile in the tile atlas? Just "selection"? and do you know what this actually changes in the resource? The .tres file for the TileSet remains unchanged when you do this in the gui, its almost like the "selection state" of tiles in the TileSet (greyed out or not behavior) is saved somewhere in the godot session data, idk

Its clear in the gui how it works, but something is giving me the feeling that the following process is not straight forward in code:

generate and save TileSet resource -> create TileMapLayer with previously saved TileSet -> Fill TileMapLayer with tiles from the TileSet.

thin flicker
# lost cloud do you know what it is called when you "click" on a tile in the tile atlas? Just...

I'm not sure what it is called but I know what you mean. I'm not too sure how to fix your issue unfortunately. For a tileset that small it wouldn't take long to set it up through the GUI but obviously if you plan to generate a lot of these that isn't ideal. Maybe try asking on the forums or if you think it is a bug open an issue on https://github.com/godotengine/godot

GitHub

Godot Engine – Multi-platform 2D and 3D game engine - godotengine/godot

lost cloud
lost cloud
#

bumping this again since I seem to have found the resource level attribute that is getting set when i click on the tile. But the work around is very ugly in my opinion and probably not the correct way.

but its a work around i guess for now:

https://github.com/godotengine/godot/issues/98991#issuecomment-2544996609

workaround

atlas_source.set("0:1/0", 0)
atlas_source.set("0:2/0", 0)
atlas_source.set("0:3/0", 0)
atlas_source.set("0:0/0", 0)

but also its been tracked as a bug now, so i think it will be fixed perhaps.. hopefully. I will keep this thread unresolved i think until then?

GitHub

Tested versions Reproducible in: v4.3.stable.official [77dcf97] Non reproducible in: v4.2 (as TileMapLayer does not exist) System information Godot v4.3.stable - Windows 10.0.22631 - Vulkan (Mobile...

thin flicker
#

Did you try the fix suggested by kleonc? If that works I'd say that this issue is resolved.