UnityC# Schema Sync error

When I starting GetInstanceAsync, I got an error below:

Realms.Exceptions.RealmException: The following changes cannot be made in additive-only schema mode:

  • Property ‘player._id’ has been made optional.
  • Property ‘player.authType’ has been made optional.
  • Property ‘player.deviceUID’ has been made optional.
  • Property ‘player.onlineState’ has been made optional.

This is my FlexibleSyncConfiguration

           var config = new FlexibleSyncConfiguration(MyApp.CurrentUser) {
               PopulateInitialSubscriptions = (realm) => {
                   var players = realm.All<DBPlayer>().Where(a => a.ID.ToString() == MyApp.CurrentUser.Id);
                   realm.Subscriptions.Add(players, new SubscriptionOptions() { Name = "player" });
               }
           };
           MyRealm = await Realm.GetInstanceAsync(config);

I don’t know where is different from my schema and atlas schema. They are both set to required field.

I found a generated ‘DBPlayer_generated’ by unity realm sdk, it may be the problem. It set some field to nullable is true, but my player.cs is not nullable field. Now, I am finding the document about how to make it correct.

Solved it.
I had to add the ‘required’ property for the string type. Although I eventually found this information in the documentation, it was easy to overlook. I suggest that the auto-generated schema example in the web UI should include it.

The issue is that the generated models assume that nullable reference types are enabled in your project, which is the default for regular .NET projects, but it isn’t for Unity. We have an item in the backlog to allow customizing that, but haven’t gotten to it yet.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.