@@ -47,22 +47,24 @@ func _validate_property(property: Dictionary) -> void:
47
47
property .hint_string = "/user/hand_tracker/left,/user/hand_tracker/right"
48
48
49
49
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
+
50
58
# Called every frame. 'delta' is the elapsed time since the previous frame.
51
59
func _process (delta : float ) -> void :
52
60
# Skip when running in the engine
53
61
if Engine .is_editor_hint ():
54
62
return
55
63
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 :
58
66
return
59
67
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
-
66
68
# Save the active pose before updates (to report changes)
67
69
var active_pos := _current_pose
68
70
@@ -112,3 +114,9 @@ func _process(delta: float) -> void:
112
114
active_pos = _current_pose
113
115
if active_pos :
114
116
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