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

[BUG] Serialization Error When Using XRI 3 + Unity 6 #958

Open
Mr-Kill opened this issue Nov 28, 2024 · 2 comments · May be fixed by #961
Open

[BUG] Serialization Error When Using XRI 3 + Unity 6 #958

Mr-Kill opened this issue Nov 28, 2024 · 2 comments · May be fixed by #961
Assignees
Labels
Type: Bug A problem with an existing feature that can be fixed with the next patched release.

Comments

@Mr-Kill
Copy link

Mr-Kill commented Nov 28, 2024

Describe the bug

When using MRTK3 in Unity 6, an exception is thrown during serialization because the ToString() method is called, which is not allowed during serialization in Unity. The error originates from the InteractionModeManager MonoBehaviour on the MRTK Interaction Manager game object and involves the MixedReality.Toolkit.SerializableDictionary.

To reproduce

Steps to reproduce the behavior:

  1. Create a new Unity project using version 6000.0.23f1.
  2. Import the XRI3 and MRTK3 packages into the project.
  3. Add the MRTK XR Rig prefab to your scene.
  4. Find the MRTK Interaction Manager GameObject.
  5. In the Inspector - Interactor Group Mappings - Entries, press the Add button at the bottom of the list.
  6. Observe the error in the Unity Console.

Expected behavior

No exception should occur and add a new item in this Entries list.

Screenshots

Screenshot_241128_20_35

Your setup (please complete the following information)

  • Unity Version 6000.0.23f1
  • MRTK Version or Commit [v4.0]
  • XRI [v3.0]

Target platform (please complete the following information)

  • Meta Quest 3
  • OpenXR
@Mr-Kill Mr-Kill added Needs: Triage Needs to be triaged. Type: Bug A problem with an existing feature that can be fixed with the next patched release. labels Nov 28, 2024
@whebertML
Copy link
Contributor

whebertML commented Dec 10, 2024

Notes on this issue:

  • The error stems from the default Inspector behavior of the add (+) button initially duplicating the last entry, and when that is attempted to be deserialized back to the underlying dictionary, it causes a duplicate key exception in the below code within SerializableDictionary.cs, showing up as the "ToString is not allowed..." in the log (which is a bit of a red herring).
        void ISerializationCallbackReceiver.OnAfterDeserialize()
        {
            this.Clear();

            foreach (SerializableDictionaryEntry entry in entries)
            {
                this.Add(entry.Key, entry.Value);   //<--- duplicate key argument exception when clicking + with an existing entry
            }
        }
  • A simple solution would be to modify the above line to this.TryAdd(entry.Key, entry.Value), however, that has the result of the add (+) button being essentially ignored as no duplicates will be added, so the user won't be able to manually add any entry, only remove.
  • But this brings up a bigger overall question, is SerializableDictionary fields intended for direct +/- manual modification in the Inspector anyway? Most other uses of this type of field seem to get initialized either at runtime or in code in some other way, not via Inspector from what I could see.
    • In the case of InteractionModeManager, one solution would be to draw the serializable dictionary in a custom way, not providing the +/- buttons, just a view of the list, along with the already existing "Init Controllers" button that can initialize it.
    • Another possible solution is to modify SerializableDictionary.cs to have special handling of the serialized entry list while in Editor during serialization/deserialization to temporarily allow duplicates, with only the first duplicate entry being stored in the underlying dictionary. I have made an initial attempt at this and it seems to work fine, but the bigger question of intent for manual modification of SerializedDictionary should be answered first I think). And not sure if this opens a can of worms...

@whebertML
Copy link
Contributor

whebertML commented Dec 18, 2024

Potential fixes:

[feature/XRI3] branch: #962
[main] branch: #961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug A problem with an existing feature that can be fixed with the next patched release.
Projects
None yet
3 participants