Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_cell() and get_cell_instance() to TileMapLayer #11687

Open
Sharaf5 opened this issue Feb 2, 2025 · 2 comments
Open

Add get_cell() and get_cell_instance() to TileMapLayer #11687

Sharaf5 opened this issue Feb 2, 2025 · 2 comments
Labels

Comments

@Sharaf5
Copy link

Sharaf5 commented Feb 2, 2025

Describe the project you are working on

2D infinite map multiplayer game where each tile has some data to represent

Describe the problem or limitation you are having in your project

I have a TileMapLayer where tiles are scene collections
each scene is attatched to a script that change it's state according to some condition
I need to pass data from the TileMapLayer to the tile scene instance when I found no way to directly interact with that layer unless using get_child()

and to the point : I called this on the child node

func _ready():
	print('[Tile] parent is : ', get_parent().name)

and this on the TileMapLayer

func _ready():
	print('[TileMapLayer] children ', get_children())

and get this

[TileMapLayer] children []
(251) [Tile] parent is : parent_layer

the issue is clear : the TileMapLayer is fully rendered and ready, then the instances is added in places

off course this behavior should stay the same, otherwise : the _ready func of TileMapLayer wont be called

the issue now is that we can access parent from children but not the opposite when working with procedual data and tiles that are set and unset

Describe the feature / enhancement and how it helps to overcome the problem or limitation

get_cell() and get_cell_instance() are not the oposite of setter 'set_cell' as they should returnt the node of the child if the cell is not empty, and not the propereties of the TileMapLayer itself

of course you could change names to what you want

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Node TileMapLayer.get_cell_instance( coords : Victor2i )

should be given a Victor2i representing coordinates of cell

  • if cell is set (either manually or via a func like set_cell( ... ) with scene collection instance : this func returns that instance ( even not ready instances if they was set )
  • if not set : this func returns null

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not few lines but it has 2 other complex alternatives

  1. complex global signal system ( very much code to care about )
  2. to handle data via each instance : this impact performance a lot as each instance ( let's say in my case 1000+ ) should have the same loops and checks running in the same time, however if there is a way to get

Is there a reason why this should be core and not an add-on in the asset library?

it's cant be added as add-on ( as far as I know )

@Calinou Calinou changed the title [TileMapLayer] get_cell() and get_cell_instance() Add get_cell() and get_cell_instance() to TileMapLayer Feb 2, 2025
@AThousandShips
Copy link
Member

@Sharaf5
Copy link
Author

Sharaf5 commented Feb 3, 2025

@AThousandShips I see it's a very similar issue

that issue is for TileMap not TileMapLayer

however

  • the workaround wont be helpful where we need to access tile scenes inside _ready from TileMapLayer
  • what I suggest is similar to get_children() or get_node() but it should return the children even if not fully ready so one could schedual actions once rather than recalling the same function for each tile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants