Skip to content

Commit

Permalink
This change triggers visibility_changed notifications the 2D scene of…
Browse files Browse the repository at this point in the history
… a Viewport2Din3D (#659)
  • Loading branch information
Malcolmnixon authored Sep 20, 2024
1 parent f68e60a commit 855ea7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- Allow grab-points and poses to work with different types of hand trackers
- Add end_xr support to StartXR
- Fixed vignette shader
- Add visibility_changed notifications to Viewport2Din3D hosted scenes
- Invisible Viewport2Din3D now disable physics and viewport updates

# 4.3.3
- Fix Viewport2Din3D property forwarding
Expand Down
20 changes: 18 additions & 2 deletions addons/godot-xr-tools/objects/viewport_2d_in_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func _ready():
# Listen for pointer events on the screen body
$StaticBody3D.connect("pointer_event", _on_pointer_event)

# Update enabled based on visibility
visibility_changed.connect(_on_visibility_changed)

# Apply physics properties
_update_screen_size()
_update_enabled()
Expand Down Expand Up @@ -340,6 +343,19 @@ func _process(delta):
set_process(false)


# Handle visibility changed
func _on_visibility_changed() -> void:
# Fire visibility changed in scene
if scene_node:
scene_node.propagate_notification(
CanvasItem.NOTIFICATION_VISIBILITY_CHANGED)

# Update collision and rendering based on visibility
_update_enabled()
_dirty |= _DIRTY_UPDATE
_update_render()


## Set screen size property
func set_screen_size(new_size: Vector2) -> void:
screen_size = new_size
Expand Down Expand Up @@ -442,7 +458,7 @@ func _update_enabled() -> void:
if Engine.is_editor_hint():
return

$StaticBody3D/CollisionShape3D.disabled = !enabled
$StaticBody3D/CollisionShape3D.disabled = !enabled or not is_visible_in_tree()


# Collision layer update handler
Expand Down Expand Up @@ -542,7 +558,7 @@ func _update_render() -> void:
# Update once. Process function used for editor refreshes
$Viewport.render_target_update_mode = SubViewport.UPDATE_ONCE
set_process(true)
elif update_mode == UpdateMode.UPDATE_ONCE:
elif update_mode == UpdateMode.UPDATE_ONCE or not is_visible_in_tree():
# Update once. Process function not used
$Viewport.render_target_update_mode = SubViewport.UPDATE_ONCE
set_process(false)
Expand Down

0 comments on commit 855ea7f

Please sign in to comment.