Fix Control resizing wrongly after "change type" in editor #91804
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #78779
This bug has been bothering me for a while now, so I decided to tackle it once and for all. Yes it's a hacky fix, but since nobody has stepped up with a proper solution so far, I'd argue this is better than keeping this bug around for even longer.
Similar (six year old!) hacks are also found right below where I did my change, for making other node types work properly with this editor feature. So maybe this method is flawed in some way?
Note that this does NOT fix the undo issues that come with this (so undoing a "change type" may still cause the control to end up wrongly sized). There are similar issues with the editor showing outdated sizes, or undo/redo not reverting this, so it's likely a more fundamental issue at play.
Background
See this very helpful comment for some details.
The PR #78009 made it so that Control updates its size cache in a lot more places, including when entering the tree (
NOTIFICATION_THEME_CHANGED
).As I understand it, the editor's "replace by" feature (used by "change type") works by first calling
Node::replace_by
and then re-applying same-named properties. However, sincereplace_by
also adds the node to the scene tree, the size is recomputed through_size_changed()
.I'm not exactly sure why it ends up using the parent viewport's size in this case, instead of the project settings size, but this is the best fix I could come up with.
Tried changing
Control::get_parent_anchorable_rect
logic a bunch, but it doesn't seem to be the culprit from my understanding. Don't want to remove/delay the problematic_size_changed()
call since it seems to have fixed a bunch of bugs.