Search Unity

Question Development Build makes accessing any Sprite fields hang up

Discussion in 'Editor & General Support' started by hrkm, Mar 14, 2023.

  1. hrkm

    hrkm

    Joined:
    Oct 21, 2013
    Posts:
    13
    I have a game object that contains List<Sprite> 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:
    Code (CSharp):
    1. private PlayerProfile.CollectibleAddOn FindByName(string name)
    2.     {
    3.         Debug.LogFormat("Are there addOns? " + StaticGameSettings.Profile.AddOns.Count);
    4.         for (int i = 0; i < StaticGameSettings.Profile.AddOns.Count; i++)
    5.         {
    6.             var addOn = StaticGameSettings.Profile.AddOns[i];
    7.             Debug.LogFormat("Comparing:  " + name + " with " + addOn.Sprite.name);
    8.             if (addOn.Sprite.name == name) return addOn;
    9.         }
    10.         return null;
    11.         //return StaticGameSettings.Profile.AddOns.FirstOrDefault(a => a.Sprite.name == name);
    12.     }
    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... :(
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    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.
     
  3. hrkm

    hrkm

    Joined:
    Oct 21, 2013
    Posts:
    13
    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.
     
  4. hrkm

    hrkm

    Joined:
    Oct 21, 2013
    Posts:
    13
    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.