diff --git a/CHANGELOG.md b/CHANGELOG.md index 3298d08cb..9be653d4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- Fix `SentryMonoBehavior` instance being removed on scene switch in WebGL ([#1754](https://github.com/getsentry/sentry-unity/pull/1754)) + ### Dependencies - Bump Java SDK from v7.12.0 to v7.13.0 ([#1751](https://github.com/getsentry/sentry-unity/pull/1751)) diff --git a/src/Sentry.Unity/SentryMonoBehaviour.cs b/src/Sentry.Unity/SentryMonoBehaviour.cs index 95895f252..40eb96808 100644 --- a/src/Sentry.Unity/SentryMonoBehaviour.cs +++ b/src/Sentry.Unity/SentryMonoBehaviour.cs @@ -120,7 +120,15 @@ internal ISentrySystemInfo SentrySystemInfo // Note: Awake is called only once and synchronously while the object is built. // We want to do it this way instead of a StartCoroutine() so that we have the context info ASAP. - private void Awake() => CollectData(); + private void Awake() + { + // This prevents object from being destroyed when unloading the scene since using HideFlags.HideAndDontSave + // doesn't guarantee its persistence on all platforms i.e. WebGL + // (see https://github.com/getsentry/sentry-unity/issues/1678 for more details) + DontDestroyOnLoad(gameObject); + + CollectData(); + } internal void CollectData() {