Clear the previously set state when configuring for a new scene root node
Saving a subscene causes the main scene to be re-instantiated. And the resource instance in the main scene will be reused when the main scene is re-instantiated. So for resources with `resource_local_to_scene` enabled, resetting state may be necessary (at least for `ViewportTexture`).
This commit is contained in:
parent
f7bc653cbe
commit
4795c3cdfa
|
@ -239,6 +239,7 @@ void Resource::configure_for_local_scene(Node *p_for_scene, HashMap<Ref<Resource
|
||||||
List<PropertyInfo> plist;
|
List<PropertyInfo> plist;
|
||||||
get_property_list(&plist);
|
get_property_list(&plist);
|
||||||
|
|
||||||
|
reset_local_to_scene();
|
||||||
local_scene = p_for_scene;
|
local_scene = p_for_scene;
|
||||||
|
|
||||||
for (const PropertyInfo &E : plist) {
|
for (const PropertyInfo &E : plist) {
|
||||||
|
@ -382,6 +383,10 @@ void Resource::setup_local_to_scene() {
|
||||||
emit_signal(SNAME("setup_local_to_scene_requested"));
|
emit_signal(SNAME("setup_local_to_scene_requested"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Resource::reset_local_to_scene() {
|
||||||
|
// Restores the state as if setup_local_to_scene() hadn't been called.
|
||||||
|
}
|
||||||
|
|
||||||
Node *(*Resource::_get_local_scene_func)() = nullptr;
|
Node *(*Resource::_get_local_scene_func)() = nullptr;
|
||||||
void (*Resource::_update_configuration_warning)() = nullptr;
|
void (*Resource::_update_configuration_warning)() = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,8 @@ protected:
|
||||||
void _set_path(const String &p_path);
|
void _set_path(const String &p_path);
|
||||||
void _take_over_path(const String &p_path);
|
void _take_over_path(const String &p_path);
|
||||||
|
|
||||||
|
virtual void reset_local_to_scene();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Node *(*_get_local_scene_func)(); //used by editor
|
static Node *(*_get_local_scene_func)(); //used by editor
|
||||||
static void (*_update_configuration_warning)(); //used by editor
|
static void (*_update_configuration_warning)(); //used by editor
|
||||||
|
|
|
@ -87,12 +87,7 @@ void ViewportTexture::setup_local_to_scene() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
|
void ViewportTexture::reset_local_to_scene() {
|
||||||
if (path == p_path) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
path = p_path;
|
|
||||||
vp_changed = true;
|
vp_changed = true;
|
||||||
|
|
||||||
if (vp) {
|
if (vp) {
|
||||||
|
@ -104,6 +99,16 @@ void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
|
||||||
proxy_ph = RS::get_singleton()->texture_2d_placeholder_create();
|
proxy_ph = RS::get_singleton()->texture_2d_placeholder_create();
|
||||||
RS::get_singleton()->texture_proxy_update(proxy, proxy_ph);
|
RS::get_singleton()->texture_proxy_update(proxy, proxy_ph);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
|
||||||
|
if (path == p_path) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = p_path;
|
||||||
|
|
||||||
|
reset_local_to_scene();
|
||||||
|
|
||||||
if (get_local_scene() && !path.is_empty()) {
|
if (get_local_scene() && !path.is_empty()) {
|
||||||
setup_local_to_scene();
|
setup_local_to_scene();
|
||||||
|
|
|
@ -70,6 +70,8 @@ class ViewportTexture : public Texture2D {
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
|
virtual void reset_local_to_scene() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_viewport_path_in_scene(const NodePath &p_path);
|
void set_viewport_path_in_scene(const NodePath &p_path);
|
||||||
NodePath get_viewport_path_in_scene() const;
|
NodePath get_viewport_path_in_scene() const;
|
||||||
|
|
Loading…
Reference in New Issue