Search Unity

Question How to remove or stabilize "rid" data?

Discussion in 'Localization Tools' started by Peter77, Jan 12, 2024.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Every time I update a StringTableCollection from Google Sheets, it changes the value of "rid" for existing entries. This frequently results in merge conflicts.

    I am curious about the purpose of this "rid" and whether there is a way to either remove it or stabilize it in order to prevent merge conflicts.

    upload_2024-1-12_11-5-55.png
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,276
    The rid comes from the SerializeReference system which we use for the metadata. It is supposed to be stable though. Could you please file a bug report so we can investigate? Maybe there's something we can do in the package to stabilize it.
     
    Peter77 and spiney199 like this.
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Thank you for the prompt support. I'm trying to create an isolated test case perhaps next when if I get the time for it. I hope it's reproducible outside of the project where it's occurring, because I'm not in the position to share it.

    Has this problem never occurred before? Perhaps it's a problem related to the project somehow. Do you have any pointers where I could start debugging it?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,276
    I can't say if its happened before, it's not something I usually check for.
    My theory is that the metadata is recreated when the pull occurs which results in new instances and so new rids. What metadata is it using, is it something custom or one of our own?
    It could be that we just need to update the metadata and not replace it.

    There is a scripting API that lets you query and control the id values https://docs.unity3d.com/ScriptReference/Serialization.ManagedReferenceUtility.html
     
    Peter77 likes this.
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    I was able to reproduce the issue in an isolated test project. I filed bug-report IN-66028. It would be great if the problem could be addressed relatively soon.
     
    karl_jones likes this.
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    karl_jones and halley like this.
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,276
    Hi Peter,

    This is an interesting one!
    We've got a bit of a clash between the Key Comment Column and the Max Length Column. The root of the problem is that MaxLengthMetadata inherits from Comment. So, when the Key Comment Column fetches metadata using
    keyEntry.Metadata.GetMetadata<Comment>()
    , it ends up treating MaxLengthMetadata as just another Comment.

    Now, when the comment column is empty, it wipes out the comment metadata. Then, your column code kicks in, notices the missing metadata, and creates a fresh one. Each new instance requires a new RID. You may have noticed that this only happens for entries with empty comments in the Google sheet.

    upload_2024-1-25_11-57-8.png

    One way to fix it is by making the Key Comment Column work only with Comment and not with inherited types. But I'm not too keen on that idea because inherited types can be pretty handy.

    Let's tweak the inheritance of MaxLengthMetadata to use IMetadata instead. That means adding a new property to replace the old one. For example, we could do something like this:

    Code (csharp):
    1.  [Serializable]
    2.  [Metadata(AllowedTypes = MetadataType.SharedStringTableEntry, AllowMultiple = false, MenuItem = "Max Length")]
    3.  public class MaxLengthMetadata : IMetadata
    4.  {
    5.      [SerializeField]
    6.      [TextArea(1, int.MaxValue)]
    7.      string m_CommentText = "Comment Text";
    8.  
    9.      public string CommentText
    10.      {
    11.          get => m_CommentText;
    12.          set => m_CommentText = value;
    13.      }
    14.  
    15.      public int MaxLength;
    16.  
    17.      public MaxLengthMetadata()
    18.      {
    19.          MaxLength = 0;
    20.      }
    21.  }
     
    Last edited: Jan 25, 2024
  8. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Hi Karl,

    thank you for looking into the issue. Great that it's an issue with my code, so I can fix it right way. Your excellent support in this forum is greatly appreciated.
     
    karl_jones likes this.