@@ -111,6 +111,9 @@ void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
111
111
if (get_local_scene () && !path.is_empty ()) {
112
112
setup_local_to_scene ();
113
113
} else {
114
+ if (path.is_empty ()) {
115
+ vp_changed = false ;
116
+ }
114
117
emit_changed ();
115
118
}
116
119
}
@@ -121,29 +124,23 @@ NodePath ViewportTexture::get_viewport_path_in_scene() const {
121
124
122
125
int ViewportTexture::get_width () const {
123
126
if (!vp) {
124
- if (!vp_pending) {
125
- ERR_PRINT (" Viewport Texture must be set to use it." );
126
- }
127
+ _err_print_viewport_not_set ();
127
128
return 0 ;
128
129
}
129
130
return vp->size .width ;
130
131
}
131
132
132
133
int ViewportTexture::get_height () const {
133
134
if (!vp) {
134
- if (!vp_pending) {
135
- ERR_PRINT (" Viewport Texture must be set to use it." );
136
- }
135
+ _err_print_viewport_not_set ();
137
136
return 0 ;
138
137
}
139
138
return vp->size .height ;
140
139
}
141
140
142
141
Size2 ViewportTexture::get_size () const {
143
142
if (!vp) {
144
- if (!vp_pending) {
145
- ERR_PRINT (" Viewport Texture must be set to use it." );
146
- }
143
+ _err_print_viewport_not_set ();
147
144
return Size2 ();
148
145
}
149
146
return vp->size ;
@@ -163,14 +160,18 @@ bool ViewportTexture::has_alpha() const {
163
160
164
161
Ref<Image> ViewportTexture::get_image () const {
165
162
if (!vp) {
166
- if (!vp_pending) {
167
- ERR_PRINT (" Viewport Texture must be set to use it." );
168
- }
163
+ _err_print_viewport_not_set ();
169
164
return Ref<Image>();
170
165
}
171
166
return RS::get_singleton ()->texture_2d_get (vp->texture_rid );
172
167
}
173
168
169
+ void ViewportTexture::_err_print_viewport_not_set () const {
170
+ if (!vp_pending && !vp_changed) {
171
+ ERR_PRINT (" Viewport Texture must be set to use it." );
172
+ }
173
+ }
174
+
174
175
void ViewportTexture::_setup_local_to_scene (const Node *p_loc_scene) {
175
176
// Always reset this, even if this call fails with an error.
176
177
vp_pending = false ;
0 commit comments