Hello! Just came here from the stream that Luce and @nraboy hosted, classic Unity experience (I teach Unity to first-timers a lot, so I always squirm when I see even seasoned software pros get stuck :))
But here’s my question / issue:
Debug.Log($"Awaiting connection to Realm App <color=green>censored</color>:");
_app = Realms.Sync.App.Create(RealmAppID);
_user = await _app.LogInAsync(Credentials.EmailPassword("test@mail.domain", "password"));
I have some code like this and it works great with Realm / Realm Sync. But it only works once, so I hit play, it works, then it fails. Once I have any code changes that trigger a recompile, it works.
Quick repro video of what this feels like:
It hangs on the await in the last statement of the code snippet above.
This is caused by Unity not reloading the .NET Domain, which is an advanced option that can be disabled in Project Settings->Editor->Enter Play Mode Settings. Recompiles always trigger domain reloads, which is why that alleviates the problem temporarily. This setting is used a lot by devs around the world because it seriously speeds up iteration time as projects grow - normally, Unity reloads the Domain whenever the Play button is pressed, but that quickly takes 1, 2, or more seconds (especially in DOTS projects or mature production code bases). It does come with some caveats that require slightly cleaner coding practices.
Usually, this sort of “run-once” behaviour is an indicator that some resources that live in a static context aren’t properly unloaded or closed. A acceptable fix would be to expose some functions that manually control the lifecycle of Realm’s runtime that does “nothing” on first run but will re-initialize all static fields and singletons with null, so they will be properly recreated as needed.