Search Unity

Bug Localized Texture on Material gets Lost

Discussion in 'Localization Tools' started by maris_admin, Nov 24, 2022.

  1. maris_admin

    maris_admin

    Joined:
    May 7, 2021
    Posts:
    6
    I have tried several different implementations of changing the main texture on an material using the localization package 1.3.2 in Unity 2020.3.22f1 (I have not upgraded to 1.4.2 because this crashed my build). My approaches all work because the right texture is set for the material, this is not the issue I am facing.

    The issue that occurs is when I change locale/language, the material somehow loses track of the assigned texture. This also happens when I only set the texture through code when the gameobject is loaded, the texture/material should not change afterwards. When I code it so the texture actually changes when I change locale, the material still loses the texture during the time I changed locale and the time it takes Unity to load the new texture. This issue only occurs in my android builds (tested on multiple device) but not in the editor.

    Screenshot_20221124-140718.jpg
    Screenshot_20221124-140726.jpg

    The following is only called on start and should not change the material/texture afterwards.
    Code (CSharp):
    1.         [SerializeField] private LocalizedAsset<Texture> localizedTexture;
    2.         [SerializeField] private MeshRenderer renderer;
    3.         [SerializeField] private int matIndex;
    4.  
    5.         private void Start()
    6.         {
    7.             renderer.materials[matIndex].mainTexture = localizedTexture.LoadAsset();
    8.         }

    I just call the following method using the Localize Texture Event component. This changes the texture each time locale is changed.
    Code (CSharp):
    1.         public void SetTexture(Texture tex)
    2.         {
    3.             renderer.materials[matIndex].mainTexture = tex;
    4.         }
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    What do you mean it crashes your build? Can you file a bug report for this, please?

    I dont see anything wrong with your code. Are you using preloading on the asset tables? There were issues with preloading that could cause the assets to become unloaded, this was fixed in 1.4.2.
     
  3. maris_admin

    maris_admin

    Joined:
    May 7, 2021
    Posts:
    6
    Yes, I am preloading the tables.

    I am not sure what cause my build not work. I use a "master" UI scene which stays loaded the entire game and is also responsible for loading/unloading scenes. This UI scene contains localized events for text and such. This is the first scene that gets loaded, but with 1.4.2 it won't load and the game remains stuck on the splash screen. I will make a bug report for this also.
     
    karl_jones likes this.
  4. maris_admin

    maris_admin

    Joined:
    May 7, 2021
    Posts:
    6
    Should I report the bug via a new thread or via the editor?
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    maris_admin likes this.