Skip to content

Commit 28e9296

Browse files
committed
fix(SnapDropZone): ensure force snap object state is saved correctly
There was an issue with the Snap Drop Zone that if on scene load an interactable object was to be snapped to it, the order of load would mean that the interactable object would not have completed set up and therefore would not save the state of the interactable object on force snap. The fix is to ensure all force snaps happen at end of frame, removing any race conditions with script load order.
1 parent e75fc1e commit 28e9296

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

Assets/VRTK/Prefabs/Resources/Scripts/VRTK_SnapDropZone.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,12 @@ public virtual void ForceSnap(GameObject objectToSnap)
182182
VRTK_InteractableObject ioCheck = objectToSnap.GetComponentInParent<VRTK_InteractableObject>();
183183
if (ioCheck != null)
184184
{
185-
ioCheck.SaveCurrentState();
186185
StopCoroutine("AttemptForceSnapAtEndOfFrame");
187186
if (ioCheck.IsGrabbed())
188187
{
189188
ioCheck.ForceStopInteracting();
190-
StartCoroutine(AttemptForceSnapAtEndOfFrame(objectToSnap));
191-
}
192-
else
193-
{
194-
AttemptForceSnap(objectToSnap);
195189
}
190+
StartCoroutine(AttemptForceSnapAtEndOfFrame(ioCheck));
196191
}
197192
}
198193

@@ -684,10 +679,11 @@ protected virtual void AttemptForceSnap(GameObject objectToSnap)
684679
OnTriggerStay(objectToSnap.GetComponentInChildren<Collider>());
685680
}
686681

687-
protected virtual IEnumerator AttemptForceSnapAtEndOfFrame(GameObject objectToSnap)
682+
protected virtual IEnumerator AttemptForceSnapAtEndOfFrame(VRTK_InteractableObject objectToSnap)
688683
{
689684
yield return new WaitForEndOfFrame();
690-
AttemptForceSnap(objectToSnap);
685+
objectToSnap.SaveCurrentState();
686+
AttemptForceSnap(objectToSnap.gameObject);
691687
}
692688

693689
protected virtual void ToggleHighlight(Collider collider, bool state)

0 commit comments

Comments
 (0)