Development Build makes accessing any Sprite fields hang up

I have a game object that contains List in it. I assigned the sprites by drag&drop in the Unity Editor.

I have also this piece of code that tries to read the sprites data and compare the name:

private PlayerProfile.CollectibleAddOn FindByName(string name)
    {
        Debug.LogFormat("Are there addOns? " + StaticGameSettings.Profile.AddOns.Count);
        for (int i = 0; i < StaticGameSettings.Profile.AddOns.Count; i++)
        {
            var addOn = StaticGameSettings.Profile.AddOns[i];
            Debug.LogFormat("Comparing:  " + name + " with " + addOn.Sprite.name);
            if (addOn.Sprite.name == name) return addOn;
        }
        return null;
        //return StaticGameSettings.Profile.AddOns.FirstOrDefault(a => a.Sprite.name == name);
    }

If I build with Development Build toggle off, everything works perfectly fine.

If I build with Development Build toggle on, the above function will print the first line with Count=27, and it will never print the second line, where I’m fetching addOn.Sprite.name. If instead I fetch any other property assigned to the addOn class (e.g. addOn.equipped which is a boolean) it prints the value correctly, and I did verify that addOn.Sprite is not a null.

There are no logs in the console that would suggest any sort of exception being thrown, but that function simply stops executing the moment I try to access properties of Sprite. Again - without Development Build everything works properly and the comparison is successful.

At first I blamed LINQ (the commented out part), but it looks like it’s not related to this. I’m using Unity 2021.3.14f1. Any help in debugging this is much appreciated!

I need the development build so that I can run profiler on my game… :frowning:

Sounds like the typical behavior when you try to access Unity objects in a thread other than the main thread. Where is this code being called? If it’s not on the main thread your thread will be killed unceremoniously.

Sounds like a good point, but why would it work perfectly fine in non Development Build?

I’m running this code in async section of my auth logic.

Ok, I made a code change where I would explicitly add the Sprite.name as a separate field during object initialization (which happens on main thread), and use that new field in my other part of the code mentioned in first comment, and it now works.

It must have been the non-main thread killing behavior, which maybe could be something that is being logged in development mode.