Skip to content

Commit f7d7fa1

Browse files
authored
Handle hand-tracker changes. (#15)
1 parent fafad7a commit f7d7fa1

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

addons/hand_pose_detector/hand_pose_detector.gd

+16-8
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,24 @@ func _validate_property(property: Dictionary) -> void:
4747
property.hint_string = "/user/hand_tracker/left,/user/hand_tracker/right"
4848

4949

50+
# Called when the node enters the scene tree for the first time.
51+
func _ready() -> void:
52+
# Listen for tracker changes
53+
XRServer.tracker_added.connect(_on_tracker_changed)
54+
XRServer.tracker_updated.connect(_on_tracker_changed)
55+
XRServer.tracker_removed.connect(_on_tracker_changed)
56+
57+
5058
# Called every frame. 'delta' is the elapsed time since the previous frame.
5159
func _process(delta: float) -> void:
5260
# Skip when running in the engine
5361
if Engine.is_editor_hint():
5462
return
5563

56-
# Skip if no hand pose set
57-
if not hand_pose_set:
64+
# Skip if no tracker or hand pose set
65+
if not tracker or not hand_pose_set:
5866
return
5967

60-
# Try to find the requested tracker
61-
if not tracker or tracker.name != tracker_name:
62-
tracker = XRServer.get_tracker(tracker_name) as XRHandTracker
63-
if not tracker:
64-
return
65-
6668
# Save the active pose before updates (to report changes)
6769
var active_pos := _current_pose
6870

@@ -112,3 +114,9 @@ func _process(delta: float) -> void:
112114
active_pos = _current_pose
113115
if active_pos:
114116
pose_started.emit(active_pos.pose_name)
117+
118+
119+
# If the tracker changed then try to get the updated handle
120+
func _on_tracker_changed(p_name : StringName, _type) -> void:
121+
if p_name == tracker_name:
122+
tracker = XRServer.get_tracker(tracker_name)

0 commit comments

Comments
 (0)