diff --git a/Source/Engine/UI/UICanvas.cpp b/Source/Engine/UI/UICanvas.cpp index c21281c67..3d6310ee4 100644 --- a/Source/Engine/UI/UICanvas.cpp +++ b/Source/Engine/UI/UICanvas.cpp @@ -14,6 +14,9 @@ MMethod* UICanvas_Deserialize = nullptr; MMethod* UICanvas_PostDeserialize = nullptr; MMethod* UICanvas_OnEnable = nullptr; MMethod* UICanvas_OnDisable = nullptr; +#if USE_EDITOR +MMethod* UICanvas_OnActiveInTreeChanged = nullptr; +#endif MMethod* UICanvas_EndPlay = nullptr; MMethod* UICanvas_ParentChanged = nullptr; @@ -43,6 +46,9 @@ UICanvas::UICanvas(const SpawnParams& params) UICanvas_PostDeserialize = mclass->GetMethod("PostDeserialize"); UICanvas_OnEnable = mclass->GetMethod("OnEnable"); UICanvas_OnDisable = mclass->GetMethod("OnDisable"); +#if USE_EDITOR + UICanvas_OnActiveInTreeChanged = mclass->GetMethod("OnActiveInTreeChanged"); +#endif UICanvas_EndPlay = mclass->GetMethod("EndPlay"); UICanvas_ParentChanged = mclass->GetMethod("ParentChanged"); } @@ -167,3 +173,15 @@ void UICanvas::OnTransformChanged() _box = BoundingBox(_transform.Translation); _sphere = BoundingSphere(_transform.Translation, 0.0f); } + +#if USE_EDITOR + +void UICanvas::OnActiveInTreeChanged() +{ + UICANVAS_INVOKE(OnActiveInTreeChanged); + + // Base + Actor::OnActiveInTreeChanged(); +} + +#endif diff --git a/Source/Engine/UI/UICanvas.cs b/Source/Engine/UI/UICanvas.cs index 4030b66b9..48dc36713 100644 --- a/Source/Engine/UI/UICanvas.cs +++ b/Source/Engine/UI/UICanvas.cs @@ -672,6 +672,16 @@ namespace FlaxEngine } } +#if FLAX_EDITOR + internal void OnActiveInTreeChanged() + { + if (RenderMode == CanvasRenderMode.ScreenSpace && _editorRoot != null && _guiRoot != null) + { + _guiRoot.Parent = IsActiveInHierarchy ? _editorRoot : null; + } + } +#endif + internal void EndPlay() { if (_isRegisteredForTick) diff --git a/Source/Engine/UI/UICanvas.h b/Source/Engine/UI/UICanvas.h index cb049c684..4980f7d28 100644 --- a/Source/Engine/UI/UICanvas.h +++ b/Source/Engine/UI/UICanvas.h @@ -28,4 +28,7 @@ protected: void OnEnable() override; void OnDisable() override; void OnTransformChanged() final override; +#if USE_EDITOR + void OnActiveInTreeChanged() override; +#endif };