diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index fc061cca61d..65586629e7e 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -243,7 +243,7 @@ The multisample anti-aliasing mode. A higher number results in smoother edges at the cost of significantly worse performance. A value of 4 is best unless targeting very high-end systems. - If [code]true[/code], the viewport will use [World] defined in [code]world[/code] property. + If [code]true[/code], the viewport will use a unique copy of the [World] defined in [member world]. If [code]true[/code], the objects rendered by viewport become subjects of mouse picking process. diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 89e4128699c..1ec1e869413 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2895,8 +2895,8 @@ void Viewport::unhandled_input(const Ref &p_event) { } } -void Viewport::set_use_own_world(bool p_world) { - if (p_world == own_world.is_valid()) { +void Viewport::set_use_own_world(bool p_use_own_world) { + if (p_use_own_world == own_world.is_valid()) { return; } @@ -2904,18 +2904,18 @@ void Viewport::set_use_own_world(bool p_world) { _propagate_exit_world(this); } - if (!p_world) { - own_world = Ref(); - if (world.is_valid()) { - world->disconnect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed"); - } - } else { + if (p_use_own_world) { if (world.is_valid()) { own_world = world->duplicate(); world->connect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed"); } else { own_world = Ref(memnew(World)); } + } else { + own_world = Ref(); + if (world.is_valid()) { + world->disconnect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed"); + } } if (is_inside_tree()) { diff --git a/scene/main/viewport.h b/scene/main/viewport.h index a4d22805981..8d1de3dfa80 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -527,7 +527,7 @@ public: Vector2 get_camera_coords(const Vector2 &p_viewport_coords) const; Vector2 get_camera_rect_size() const; - void set_use_own_world(bool p_world); + void set_use_own_world(bool p_use_own_world); bool is_using_own_world() const; void input(const Ref &p_event);