Strange Behaviour - Unity Realm SDK

There seems to be strange behaviour when I run my app in the editor. The first time I run it, it’s fine. The second time I run it, it crashes the unity application. Here is a sample of my code:

var app = App.Create(realmAppId);
var credentials = Credentials.ApiKey(apiKey);
var user = await app.LogInAsync(credentials);

    try
    {
        client = user.GetMongoClient(mongoClient);
        database = client.GetDatabase(databaseName);
}
catch(Exception e){ }

I am wondering if I have to handle dispose or close the connection? I am unsure.

Thank you,

Hey, the current public version of the Unity SDK is a very early preview where only the local database was tested and verified to be working. We have identified and resolved a number of issues related to the sync/remote MongoDB part of the SDK and hope to release those next week.

Nice! thanks for responding.

@theresaj We’d love to hear more about the game you are looking to build with the Realm Unity SDK - drop me a line at ian.ward@mongodb.com and I can let you fill you in on our gaming roadmap for Realm

1 Like

Hey folks. I stumbled on this thread and wanted to add my observations as we are experiencing the same behavior the OP describes.

We are doing some testing with Realm Sync and Unity as it seems like an attractive option for a future project.

Currently using 10.1.4 of the Realm Unity SDK and seeing the following:

–Logging in with emaill/pwd creds, syncing, and making changes seems to work as intended the first time after opening Unity and pressing play
----A second play always freezes the editor

–Based on what I see in the documentation (and some experimenting) it seems we need to specify a filename when we call GetInstanceAsync to get things to work as intended rather than a new .realm file being created on each sync and a resulting resync of all data
----This works properly if I only specify a filename (subsequent syncs no longer show ‘for the first time’ and current data is not resynced
----If I try to append a path (to the persistentDataPath folder for example) the editor crashes when trying to sync whether the file exists or not

–Testing falling back to offline mode (via Realm.GetInstance) after a successful sync doesn’t seem to work
----I receive ‘Incompatible histories. Expected a Realm with no or in-realm history, but found history type 3’ when attempting to open the .realm file

Hoping this is useful in some way and wondering if the bug-fixes mentioned above were included in 10.1.4?

Looking forward to efforts on this continuing as I think it would potentially be a great option for Unity developers and would like to give it a more through test-run myself.

Thanks!

The editor freezes are something we’re actively working on. You can try installing this WIP package and see if it fixes those for you.

Regarding falling back to offline mode - this is probably something we should explain more explicitly in the docs, but there’s no need to fall back to offline mode - you should continue using SyncConfiguration when opening the Realm, even if you’re offline as the data will still be on your device.

1 Like

Understood. I’ll give the file and the advice a try. Much appreciated!

@nirinchev

The WIP package is a HUGE improvement. It occasionally stops recompiling the script after a change for some reason, and I’ve had it lock up the editor a couple times, but it works flawlessly 95% of the time. More than enough to keep testing this out. It also corrected the issue I was having when adding the data path. Very much appreciated!

On the other front, thanks for the advice. After the changes I’m now able to access my Realm both on and offline.

2 Likes