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?
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.