Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug [Resolved] LocalizedString display

Discussion in 'Visual Scripting' started by abegue, Nov 19, 2021.

  1. abegue

    abegue

    Joined:
    Jan 28, 2019
    Posts:
    20
    Hello,

    I am having some trouble with using LocalizedString into Visual Scripting Graph.
    It seems that, even that the data are correctly serialized, it is not correctly displayed into the VSG variable inspector and blackboard.
    Looking at the text file, I can see that the data are here and, during runtime, it works correctly (so I don't think it is a serialization issue) but whenever I recompile (or probably reload the asset), the LocalizedString will display nothing as it has been reset. Not really convenient to work with.

    Capture.JPG

    I added the Unity.Localization into the Node library + LocalizedString into Type Options, then I generated provider for custom inspector properties.

    I though that maybe it was due to OnAfterDeserialize not being called but it looks like it is done (maybe not successfully?).

    Any idea or workaround about it? Not sure if the issue may be on Visual Scripting side or Localization side though.

    Update:

    Correction: though the data are correctly serialized, I am not sure they are correctly deserialized. Looking at the LocalizedStringPropertyDrawer, it seems that the data inside are actually empty.

    Capture.JPG

    Other curiosity:
    Temp.gif
    Starting by setting the localization key, then switching the variable order alter the LocalizedString. Resetting to its original place make the localization key reappear.
     
    Last edited: Nov 19, 2021
  2. abegue

    abegue

    Joined:
    Jan 28, 2019
    Posts:
    20
    Okay, I resolved the mystery.

    LocalizedString is a little special. When its PropertyDrawer draws it, it will do some initialization once, creating some classes based on its current value at this moment (1).

    On the Visual Scripting Graph side, things will happen in CustomPropertyDrawerInspector. A fake (temporary) SerializedProperty is created at start. Then, when OnGUI is called, the deserialized value of the LocalizedString will be set on the fake SerializedProperty.
    However, the value is set only during OnGUI but GetHeight is called before!
    Thus:
    - CustomPropertyDrawerInspector creates fake empty SerializedProperty
    - CustomPropertyDrawerInspector calls GetHeight on the SerializedProperty of the LocalizedString
    - LocalizedString need initialization to call correctly GetHeight so it initialize its data once, based on an default (empty) values.
    - CustomPropertyDrawerInspector calls EditorGUI.PropertyField
    - The PropertyDrawer of LocalizedString draws the data, based on the default values, without any chance to update with its real new data.

    I don't really now on which side the modification should be (LocalizedString not initializing itself during GetPropertyHeight or CustomPropertyDrawerInspector doing the value setting also in GetHeight or upper in code, before calling GetHeight) but I will probably go on GetHeight modification to setup the underlying value.
    So, I will go for source modifications for now (hopefully Visual Scripting package is open source).

    (1): LocalizedReferencePropertyDrawer.GetDataForProperty: l257
     
    Last edited: Nov 19, 2021
    PanthenEye and Kirsche like this.
  3. Kirsche

    Kirsche

    Joined:
    Apr 14, 2015
    Posts:
    117
    Thank you for sharing this valuable information.

    Just wanted to let future readers know I've submitted a bug report for this:

    Case 1410176
     
    abegue and PanthenEye like this.