From 3f477bb725d48e77d4f62bf9722fbe537ef683c8 Mon Sep 17 00:00:00 2001 From: Sara Date: Tue, 23 Jun 2026 11:21:43 +0200 Subject: [PATCH] feat: arealoader works on visibility/process_mode --- modules/viscosity/area_loader.cpp | 20 +++++++------------- modules/viscosity/area_loader.h | 5 ++--- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/modules/viscosity/area_loader.cpp b/modules/viscosity/area_loader.cpp index 893b89f4..073eb109 100644 --- a/modules/viscosity/area_loader.cpp +++ b/modules/viscosity/area_loader.cpp @@ -4,7 +4,7 @@ #include "viscosity/player_body.h" void AreaLoader::_bind_methods() { - BIND_HPROPERTY(Variant::OBJECT, area, PROPERTY_HINT_NODE_TYPE, "Node"); + BIND_HPROPERTY(Variant::OBJECT, area, PROPERTY_HINT_NODE_TYPE, "Node3D"); BIND_PROPERTY(Variant::BOOL, start_loaded); } @@ -12,18 +12,16 @@ void AreaLoader::body_entered(Node3D *body) { if (!cast_to(body)) { return; } - if (!this->area->is_inside_tree()) { - this->area_parent->add_child(this->area); - } + this->area->set_process_mode(PROCESS_MODE_INHERIT); + this->area->set_visible(true); } void AreaLoader::body_exited(Node3D *body) { if (!cast_to(body)) { return; } - if (this->area->is_inside_tree()) { - this->area_parent->remove_child(this->area); - } + this->area->set_process_mode(PROCESS_MODE_DISABLED); + this->area->set_visible(false); } void AreaLoader::_notification(int what) { @@ -35,17 +33,13 @@ void AreaLoader::_notification(int what) { return; case NOTIFICATION_READY: if (this->area) { - this->area_parent = this->area->get_parent(); - ERR_FAIL_COND_EDMSG(!this->area_parent, "Area does not have a valid parent"); if (!this->start_loaded) { - callable_mp(cast_to(this->area_parent), &Node::remove_child).call_deferred(this->area); + this->area->set_process_mode(PROCESS_MODE_DISABLED); + this->area->set_visible(false); } connect("body_entered", callable_mp(this, &self_type::body_entered)); connect("body_exited", callable_mp(this, &self_type::body_exited)); } return; - case NOTIFICATION_PREDELETE: - this->area->queue_free(); - return; } } diff --git a/modules/viscosity/area_loader.h b/modules/viscosity/area_loader.h index 9b8fa15e..5f2c0f07 100644 --- a/modules/viscosity/area_loader.h +++ b/modules/viscosity/area_loader.h @@ -13,11 +13,10 @@ protected: void _notification(int what); private: - Node *area{ nullptr }; - Node *area_parent{ nullptr }; + Node3D *area{ nullptr }; bool start_loaded{ false }; public: - GET_SET_FNS(Node *, area); + GET_SET_FNS(Node3D *, area); GET_SET_FNS(bool, start_loaded); };