Skip to content
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

Fix SentryMonoBehavior instance being removed on scene switch in WebGL #1754

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 9 additions & 1 deletion src/Sentry.Unity/SentryMonoBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading