From 2cb1d7508e961513fac325828e58061dde7b5c96 Mon Sep 17 00:00:00 2001 From: Kevin Foley Date: Tue, 31 May 2022 14:21:35 -0700 Subject: [PATCH] Fix FollowMeToggle's auto-follow breaking if the component is disabled (#10620) * Fix FollowMeToggle's auto-follow breaking if the component is ever disabled `FollowMeToggle` has an `AutoFollowAtDistance` feature which breaks if the `FollowMeToggle` component is ever disabled and re-enabled. This is because the `AutoFollowAtDistance` property setter checks if the `autoFollowDistanceCheck` coroutine is null before starting the coroutine. If the component is disabled, the coroutine will _stop_ but not become null. When the component is re-enabled, the coroutine does not start again because the previous instance is non-null, even though it is no longer running. This is fixed by simply setting `autoFollowDistanceCheck` to null in `OnDisable()`. * FollowMeToggle: formatting tweak Per keveleigh Co-authored-by: Kurtis Co-authored-by: Kurtis --- Assets/MRTK/SDK/Features/UX/Scripts/Slate/FollowMeToggle.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Assets/MRTK/SDK/Features/UX/Scripts/Slate/FollowMeToggle.cs b/Assets/MRTK/SDK/Features/UX/Scripts/Slate/FollowMeToggle.cs index 9c5638f4400..e9f49225887 100644 --- a/Assets/MRTK/SDK/Features/UX/Scripts/Slate/FollowMeToggle.cs +++ b/Assets/MRTK/SDK/Features/UX/Scripts/Slate/FollowMeToggle.cs @@ -183,6 +183,11 @@ private void OnEnable() // Begin the follow coroutine when enabled. AutoFollowAtDistance = autoFollowAtDistance; } + + private void OnDisable() + { + autoFollowDistanceCheck = null; + } #endregion MonoBehaviour Implementation