Skip to content

Commit 8b0278c

Browse files
authored
FIX: Fix input shutdown analytics event in editor (#803)
1 parent 7e4b564 commit 8b0278c

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Packages/com.unity.inputsystem/InputSystem/InputManager.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,6 @@ internal struct AvailableDevice
16631663

16641664
#if UNITY_ANALYTICS || UNITY_EDITOR
16651665
private bool m_HaveSentStartupAnalytics;
1666-
private bool m_HaveSentFirstUserInteractionAnalytics;
16671666
#endif
16681667

16691668
internal IInputRuntime m_Runtime;
@@ -2988,7 +2987,6 @@ internal struct SerializedState
29882987

29892988
#if UNITY_ANALYTICS || UNITY_EDITOR
29902989
public bool haveSentStartupAnalytics;
2991-
public bool haveSentFirstUserInteractionAnalytics;
29922990
#endif
29932991
}
29942992

@@ -3032,7 +3030,6 @@ internal SerializedState SaveState()
30323030

30333031
#if UNITY_ANALYTICS || UNITY_EDITOR
30343032
haveSentStartupAnalytics = m_HaveSentStartupAnalytics,
3035-
haveSentFirstUserInteractionAnalytics = m_HaveSentFirstUserInteractionAnalytics,
30363033
#endif
30373034
};
30383035
}
@@ -3051,7 +3048,6 @@ internal void RestoreStateWithoutDevices(SerializedState state)
30513048

30523049
#if UNITY_ANALYTICS || UNITY_EDITOR
30533050
m_HaveSentStartupAnalytics = state.haveSentStartupAnalytics;
3054-
m_HaveSentFirstUserInteractionAnalytics = state.haveSentFirstUserInteractionAnalytics;
30553051
#endif
30563052

30573053
////REVIEW: instead of accessing globals here, we could move this to when we re-create devices

Packages/com.unity.inputsystem/InputSystem/NativeInputRuntime.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ public Action onShutdown
134134
if (value == null)
135135
{
136136
#if UNITY_EDITOR
137-
EditorApplication.quitting -= OnShutdown;
137+
EditorApplication.wantsToQuit -= OnWantsToShutdown;
138138
#else
139139
Application.quitting -= OnShutdown;
140140
#endif
141141
}
142142
else if (m_ShutdownMethod == null)
143143
{
144144
#if UNITY_EDITOR
145-
EditorApplication.quitting += OnShutdown;
145+
EditorApplication.wantsToQuit += OnWantsToShutdown;
146146
#else
147147
Application.quitting += OnShutdown;
148148
#endif
@@ -187,11 +187,30 @@ public float pollingFrequency
187187
private Action<InputUpdateType> m_OnBeforeUpdate;
188188
private Func<InputUpdateType, bool> m_OnShouldRunUpdate;
189189
private float m_PollingFrequency = 60.0f;
190+
private bool m_DidCallOnShutdown = false;
190191
private void OnShutdown()
191192
{
192193
m_ShutdownMethod();
193194
}
194195

196+
private bool OnWantsToShutdown()
197+
{
198+
if (!m_DidCallOnShutdown)
199+
{
200+
// we should use `EditorApplication.quitting`, but that is too late
201+
// to send an analytics event, because Analytics is already shut down
202+
// at that point. So we use `EditorApplication.wantsToQuit`, and make sure
203+
// to only use the first time. This is currently only used for analytics,
204+
// and getting analytics before we actually shut downn in some cases is
205+
// better then never.
206+
207+
OnShutdown();
208+
m_DidCallOnShutdown = true;
209+
}
210+
211+
return true;
212+
}
213+
195214
private Action<bool> m_FocusChangedMethod;
196215

197216
private void OnFocusChanged(bool focus)

0 commit comments

Comments
 (0)