How to work with tiles from a scene collection?

Godot Version 4.3 Beta 1

Question

Let’s imagine a scenario. I have a Node2D that is the owner of the scene and its child node AnimatedSprite2D that will display the tile.

I save the scene as Tile.tscn, then add a scene collection to TileSet and put Tile.tscn in it.

I read that you can set such a scene as a tile by set_cell(...).

Let’s present the data about this scene collection that it has in TileSet:

source_id = 0
atlas_coords = Vector2I(0, 0) // for any scene collection, according to the documentation
alternative_tile = 0 // the number of the scene in the collection.

To place it I’ll prescribe:

pos = Vector2I(0, 0)
set_cell(pos, 0, new Vector2I(0,0), 0)

This will place the scene as a tile on pos.

Now the question is, how can I get this scene to make runtime changes, like changing the animation in AnimatedSprite2D?

Scenes from a TileSetScenesCollectionSource are added as children of the TileMap. You can use any function to get a child from Node like Node.get_child() or Node.get_node()

1 Like

Strange, I had thought of that, but when I started the project there didn’t seem to be any children in the REMOTE tab, but thanks, I’ll check it out when I have time

Only issue with using .get_child() in this situation is that it’s tricky to identify exactly which scene collection object you’re dealing with if you are trying to target specific instances across the map.

Example :

You create a door scene object that has a property of ‘key_colour’ to denote what type of key can open said door.

You add door scene to TileMap Scene collection and set main script to retrieve doors as a child array.

You now want to set specific doors at specific map positions to have a certain key colours. How would this be achieved ?

Would be great if TileMap (TileMapLayer) developer could allow access to properties when placed on map.

Feel free to search if a proposal exists for that or open a new proposal here GitHub - godotengine/godot-proposals: Godot Improvement Proposals (GIPs)

Sadly there are a fair few similar requests that relate to this but so far hasn’t manifested into an actual solution.

Allow new Tilemap cells with scenes to return the node/scene they create · Issue #4833 · godotengine/godot-proposals · GitHub.

I’d be happy with a scene layer if it’s too awkward to implement into the current TileMapLayer.