diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index a4e27a3d166..acf4f676731 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -111,6 +111,9 @@ void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) { if (get_local_scene() && !path.is_empty()) { setup_local_to_scene(); } else { + if (path.is_empty()) { + vp_changed = false; + } emit_changed(); } } @@ -121,9 +124,7 @@ NodePath ViewportTexture::get_viewport_path_in_scene() const { int ViewportTexture::get_width() const { if (!vp) { - if (!vp_pending) { - ERR_PRINT("Viewport Texture must be set to use it."); - } + _err_print_viewport_not_set(); return 0; } return vp->size.width; @@ -131,9 +132,7 @@ int ViewportTexture::get_width() const { int ViewportTexture::get_height() const { if (!vp) { - if (!vp_pending) { - ERR_PRINT("Viewport Texture must be set to use it."); - } + _err_print_viewport_not_set(); return 0; } return vp->size.height; @@ -141,9 +140,7 @@ int ViewportTexture::get_height() const { Size2 ViewportTexture::get_size() const { if (!vp) { - if (!vp_pending) { - ERR_PRINT("Viewport Texture must be set to use it."); - } + _err_print_viewport_not_set(); return Size2(); } return vp->size; @@ -163,14 +160,18 @@ bool ViewportTexture::has_alpha() const { Ref ViewportTexture::get_image() const { if (!vp) { - if (!vp_pending) { - ERR_PRINT("Viewport Texture must be set to use it."); - } + _err_print_viewport_not_set(); return Ref(); } return RS::get_singleton()->texture_2d_get(vp->texture_rid); } +void ViewportTexture::_err_print_viewport_not_set() const { + if (!vp_pending && !vp_changed) { + ERR_PRINT("Viewport Texture must be set to use it."); + } +} + void ViewportTexture::_setup_local_to_scene(const Node *p_loc_scene) { // Always reset this, even if this call fails with an error. vp_pending = false; diff --git a/scene/main/viewport.h b/scene/main/viewport.h index edacee2d880..a18dc1f6f0f 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -63,6 +63,7 @@ class ViewportTexture : public Texture2D { bool vp_changed = false; void _setup_local_to_scene(const Node *p_loc_scene); + void _err_print_viewport_not_set() const; mutable RID proxy_ph; mutable RID proxy;