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

Scene tiles are freed and re-instantiated when its parent TileMap is removed and re-added to the tree. #92096

Closed
Gerfalerf opened this issue May 18, 2024 · 4 comments

Comments

@Gerfalerf
Copy link

Tested versions

  • Reproducible in v4.2.stable.official [46dc277]

System information

Godot v4.2.stable - Windows 10.0.19045 - GLES3 (Compatibility) - NVIDIA GeForce GTX 1080 () - Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz (8 Threads)

Issue description

When removing (but not freeing!) a TileMap from the tree, any of its child nodes that were SceneCollection tiles are freed! Then when the TileMap is re-added, they are re-instantiated from their scene file.

It should be possible to remove/re-add a TileMap from the tree without it deleting and re-instantiating all of its child Scene tiles. This erases all the state that might have set on those tiles since instantiation! This does not seem like correct or useful behavior based on how add_child and remove_child work everywhere else.

Some other notes:

  • The TileMap's non-SceneTile children are not freed in this way, which is why I expected that its SceneTile children should receive the same treatment.
  • Reparent the SceneTile somewhere else causes it to not be freed upon removal of the TileMap

Steps to reproduce

I have a minimal repro project here (also attached) that shows scene tiles being deleted/re-instantiated and their state being erased.

  1. Run the project
  2. Click on a tile (the white circles) to turn it red
  3. Click the button to remove the TileMap
  4. Click the button again to re-add the TileMap.
  5. Oh no, the tiles are white again!

Minimal reproduction project (MRP)

SceneCollectionBug.zip

@KoBeWi
Copy link
Member

KoBeWi commented May 18, 2024

Sounds like something that should've been fixed by #67330
There were multiple other bugfixes to scene tiles, so the bug might've resurfaced. This still happens with TileMapLayers in 4.3.

@Gerfalerf
Copy link
Author

Gerfalerf commented May 19, 2024

I'm trying to figure out what the right solution is, and I'm realizing a parallel issue exists with the child nodes' creation. Scene Tile child nodes are only instantiated when the TileMap first enters the tree, rather than when the TileMap is instantiated.

It seems like maybe these Scene Tile child nodes' lifetimes should be tied to the TileMap's init/free rather than its enter_tree/exit_tree. Does that make sense?

@matheusmdx
Copy link
Contributor

Bisecting poits to #79941 as the culprit:

image

@Gerfalerf
Copy link
Author

This behavior is intended. Scene Tiles are not really expected to behave like regular nodes the tree, and their lifetime is the TileMap's to manage. To get this functionality, make regular Nodes in the tree and parent them to the TileMap.
Not going to fix this issue.
#92189 (comment)

@Gerfalerf Gerfalerf closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants