-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Don't free instanced scenes when recreating tiles #67330
Conversation
d2fb3fa
to
f8f25ad
Compare
CC @groud |
Hmm, it does not look right to me. How do you know whether or not the packed scene was modified or not ? |
When exactly this can happen at runtime? |
I guess procedural modifications of the TileSet, which is possible right now. To be honest, I am not perfectly happy with that implementation. I think we should make sure somehow that the underlying PackedScene wasn't modified. This, I suppose, should be maybe done by passing an argument to the update functions ? |
I reset the instanced scenes on tileset changed, so this is handled.
The way I implemented it, only tiles that weren't instantiated previously will instantiate. Not sure what argument should be passed to preserve this behavior. You need to store the used tiles somewhere. Also not sure what you mean by modified scene. Scenes don't get modified at runtime, unless you use live edit. I'm also not 100% happy with this implementation (as I noted in the OP), but I don't have much better idea. |
Ah that's true, my bad.
The idea would be to have a
Not the scene itself, but you can replace a scene in the TileSet resource at runtime. For example using Anyway, I didn't see the cache was cleared when the TileSet was modified, so I think this implementation should be fine in the end. I feel an implementation with the added argument as I suggested could maybe be cleaner, but I am not sure about how much rewrite that would need. So well, as you prefer. :) |
What does that change exactly? Clearing cache is the same as bypassing it. You need to remove the old node and cache the new one. (although it might change something if the used cells have changed) tbh I'm not sure how scene tiles are supposed to work. I'd just make them instance and forget, no clearing. |
I think it's more about the way the code is organized right now, where a method is dedicated to each type of sources, and I avoided spreading the responsibilities over. So like, I'd rather have the scene cache cleaning the method dedicated to scene tiles rather than having it in the generic Even if I didn't have the time to implement it, and to find interesting use cases, I kind of wanted to allow users to implement their own TileSetSource if needed. So I kept things modular just in case. This special handling in the
I guess I would have added the same argument. |
Thanks! |
I think this PR made it so that it's not possible to use set_cell with a scene tile if that tile is not empty (already had a value wether it was a regular tile or a scene tile) because all tiles are added to the instantiated_scenes set, not only the scene tiles, and they are also never removed from that set (the set is only emptied when the tileset changes). See the attached MRE, left click doesn't place new tiles on the bottoom layer which already has tiles set while right click works on an empty layer above. |
Fixes #58034
Fixes #68347
Scenes are no longer re-instantiated when quadrant is recreated, including when setting cells and changing layer properties (modulate etc). Only modifying TileSet will recreate the scenes (although there's high chance they'll just get unlinked at that point...).
To me it's rather weird that the scenes are re-instanced at all. The purpose of scene collections is to put objects on your level. At no point you want them freed and recreated by the TileMap.
That said, not sure if my solution is good. Probably not 🙃