diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 7ac7ceb6bce..d78077316a7 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1383,6 +1383,15 @@ void Control::_set_position(const Point2 &p_point) { void Control::set_position(const Point2 &p_point, bool p_keep_offsets) { ERR_MAIN_THREAD_GUARD; + +#ifdef TOOLS_ENABLED + // Can't compute anchors, set position directly and return immediately. + if (saving && !is_inside_tree()) { + data.pos_cache = p_point; + return; + } +#endif + if (p_keep_offsets) { _compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor); } else { @@ -1441,6 +1450,14 @@ void Control::set_size(const Size2 &p_size, bool p_keep_offsets) { new_size.y = min.y; } +#ifdef TOOLS_ENABLED + // Can't compute anchors, set size directly and return immediately. + if (saving && !is_inside_tree()) { + data.size_cache = new_size; + return; + } +#endif + if (p_keep_offsets) { _compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor); } else { @@ -3140,6 +3157,14 @@ Control *Control::make_custom_tooltip(const String &p_text) const { void Control::_notification(int p_notification) { ERR_MAIN_THREAD_GUARD; switch (p_notification) { +#ifdef TOOLS_ENABLED + case NOTIFICATION_EDITOR_PRE_SAVE: { + saving = true; + } break; + case NOTIFICATION_EDITOR_POST_SAVE: { + saving = false; + } break; +#endif case NOTIFICATION_POSTINITIALIZE: { data.initialized = true; diff --git a/scene/gui/control.h b/scene/gui/control.h index bdb908e089c..c784d4330da 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -47,6 +47,10 @@ class ThemeContext; class Control : public CanvasItem { GDCLASS(Control, CanvasItem); +#ifdef TOOLS_ENABLED + bool saving = false; +#endif + public: enum Anchor { ANCHOR_BEGIN = 0,