First run of play mode is unable to resolve smart format string

I have a monobehavior set up with a LocalizeStringBehaviour that points to a string reference formatted like Black: {0} / {1}. The string reference has arguments set in code like this:

LocalizedString.StringReference.Arguments = new object[] {
    Value0,
    Value1
};

On a fresh run of the editor, after hitting play, the string gets resolved like so although subsequent runs the string resolves fine.

5688196--593740--upload_2020-4-8_15-55-39.png

I tracked this down to a null names property on a ListFormatter.

This property is accessed in the attached callstack.

I’ve filed a bug but it I haven’t seen the automated response come through with a bug number yet. I’ll attach it here when that happens.

Edit:

For some reason I ended up sending 3 bugs, oops.

https://fogbugz.unity3d.com/default.asp?1235523_6fdmb5nhkq9qngku
https://fogbugz.unity3d.com/default.asp?1235521_ce4ag3d473u3r3js
https://fogbugz.unity3d.com/default.asp?1235519_0lddoba424k2cbe8

5688196–593755–callstack.txt (4.9 KB)

1 Like

Hey,
This sounds familiar. I think its a bug with the SerializeReference feature that came into 2019.3.
Some properties were going null when they really never should. Ill see if I can find out the status of it.
Thanks for reporting the bug!

Edit: Found it! Unity Issue Tracker - [SerializeReference] Polymorphic instances are always recreated when applying *any* inspector value change
Looks like its not fixed yet. Ill see if its possible for us to workaround it.

Got the same error in android il2cpp-backed build.
Looks like other formatters are inherited from FormatterBase class.
Their Names field has explicit SerializeField attribute:

public abstract class FormatterBase : IFormatter
{
    [SerializeField]
    string[] m_Names;

    public string[] Names
    {
        get => m_Names;
        set => m_Names = value;
    }

    public abstract bool TryEvaluateFormat(IFormattingInfo formattingInfo);
}

And they are initiating list of names in the constructor:

[Serializable]
    public class ConditionalFormatter : FormatterBase
    {
        public ConditionalFormatter()
        {
            Names = new[] {"conditional", "cond", ""};
        }
    }

Removing ListFormatter from Smart Format in Project Settings resolved issue.

2 Likes