-
Notifications
You must be signed in to change notification settings - Fork 323
FIX: Trackedposedriver stops tracking (ISXB-1555) #2189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9bc4362
7fae50e
d45a36b
0794cde
f92539f
4197723
a10d623
29347c3
6267909
9702c42
f0e01c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -432,6 +432,7 @@ | |
protected void OnEnable() | ||
{ | ||
InputSystem.onAfterUpdate += UpdateCallback; | ||
InputSystem.onDeviceChange += OnDeviceChanged; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only thing I am thinking around this one if it truly captures what would drive an action resolve (or might cause unnecessary checking) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come (before my regression of this) it worked then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tracking was never set to None, but always kept at Position & Rotation when no tracking action was assigned. Like that there was no need to reevaluate the tracking state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There will be some amount of unnecessary checking for sure, if any (not trackable) device is connected/disconnected for instance. But I am wondering if that's so critical, it probably depends on how frequently deviceChange events happen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a HUP I think we would be fine with this and see it as an optimization if it could be reduced in the future. |
||
BindActions(); | ||
|
||
// Read current input values when becoming enabled, | ||
|
@@ -446,6 +447,7 @@ | |
{ | ||
UnbindActions(); | ||
InputSystem.onAfterUpdate -= UpdateCallback; | ||
InputSystem.onDeviceChange -= OnDeviceChanged; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -484,7 +486,7 @@ | |
else | ||
m_CurrentRotation = transform.localRotation; | ||
|
||
ReadTrackingState(hasResolvedPositionInputControl, hasResolvedRotationInputControl); | ||
ReadTrackingState(); | ||
|
||
m_IsFirstUpdate = false; | ||
} | ||
|
@@ -495,7 +497,40 @@ | |
OnUpdate(); | ||
} | ||
|
||
void ReadTrackingState(bool hasResolvedPositionInputControl, bool hasResolvedRotationInputControl) | ||
void OnDeviceChanged(InputDevice inputDevice, InputDeviceChange inputDeviceChange) | ||
{ | ||
if (m_IsFirstUpdate) | ||
return; | ||
ReadTrackingStateWithoutTrackingAction(); | ||
} | ||
|
||
/// <summary> | ||
/// React to changes of devices to stop the tracking of position / rotation or both if a device is removed, starts the tracking if | ||
/// a device is added. | ||
/// </summary> | ||
void ReadTrackingStateWithoutTrackingAction() | ||
{ | ||
var trackingStateAction = m_TrackingStateInput.action; | ||
if (trackingStateAction != null && trackingStateAction.m_BindingsCount != 0) | ||
return; | ||
|
||
var hasResolvedPositionInputControl = HasResolvedControl(m_PositionInput.action); | ||
var hasResolvedRotationInputControl = HasResolvedControl(m_RotationInput.action); | ||
|
||
// Treat an Input Action Reference with no reference the same as | ||
// an enabled Input Action with no authored bindings, and allow driving the Transform pose. | ||
// Check if we have transform and rotation controls to drive the pose. | ||
if (hasResolvedPositionInputControl && hasResolvedRotationInputControl) | ||
m_CurrentTrackingState = TrackingStates.Position | TrackingStates.Rotation; | ||
else if (hasResolvedPositionInputControl) | ||
m_CurrentTrackingState = TrackingStates.Position; | ||
else if (hasResolvedRotationInputControl) | ||
m_CurrentTrackingState = TrackingStates.Rotation; | ||
else | ||
m_CurrentTrackingState = TrackingStates.None; | ||
} | ||
|
||
void ReadTrackingState() | ||
{ | ||
var trackingStateAction = m_TrackingStateInput.action; | ||
if (trackingStateAction != null && !trackingStateAction.enabled) | ||
|
@@ -504,29 +539,16 @@ | |
m_CurrentTrackingState = TrackingStates.None; | ||
return; | ||
} | ||
|
||
if (trackingStateAction == null || trackingStateAction.m_BindingsCount == 0) | ||
{ | ||
// Treat an Input Action Reference with no reference the same as | ||
// an enabled Input Action with no authored bindings, and allow driving the Transform pose. | ||
// Check if we have transform and rotation controls to drive the pose. | ||
if (hasResolvedPositionInputControl && hasResolvedRotationInputControl) | ||
m_CurrentTrackingState = TrackingStates.Position | TrackingStates.Rotation; | ||
else if (hasResolvedPositionInputControl) | ||
m_CurrentTrackingState = TrackingStates.Position; | ||
else if (hasResolvedRotationInputControl) | ||
m_CurrentTrackingState = TrackingStates.Rotation; | ||
else | ||
m_CurrentTrackingState = TrackingStates.None; | ||
} | ||
else if (HasResolvedControl(trackingStateAction)) | ||
if (HasResolvedControl(trackingStateAction)) | ||
{ | ||
// Retain the current value if there is no resolved binding. | ||
// Since the field initializes to allowing position and rotation, | ||
// this allows for driving the Transform pose always when the device | ||
// doesn't support reporting the tracking state. | ||
m_CurrentTrackingState = (TrackingStates)trackingStateAction.ReadValue<int>(); | ||
return; | ||
} | ||
ReadTrackingStateWithoutTrackingAction(); | ||
} | ||
|
||
/// <summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this test.