Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Getting LocalizedString from addressable scriptable object

Discussion in 'Addressables' started by wingeisoftware, Sep 7, 2023.

  1. wingeisoftware

    wingeisoftware

    Joined:
    Jun 15, 2021
    Posts:
    6
    Hi all !

    I wanted to load a localizedString from a scriptableObject loaded as a an addressable from code but ran into an exception:

    Exception: Reentering the Update method is not allowed.  This can happen when calling WaitForCompletion on an operation while inside of a callback.


    This is the code i used:


    Code (CSharp):
    1. var a = anAssetReference.LoadAssetAsync();
    2. a.Completed += (handle) =>
    3. {
    4.     Debug.Log("Completed loading asset");
    5.     // Here description is a LocalizedAsset.
    6.     var b = handle.Result.description.GetLocalizedString();
    7. };
    So, what would be the correct workflow for my use case ?

    Thanks !
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    The problem here is that GetLocalizedString calls WaitForCompletion and you can not do that inside of an addressables callback.
    Can you use the asynchronous version instead? GetLocalizedStringAsync.
     
  3. wingeisoftware

    wingeisoftware

    Joined:
    Jun 15, 2021
    Posts:
    6
    Well, the async version actually never fires the Completed event.

    Logging its progress and result on the Update lifecycle event shows that its progress is stuck at 0%..

    Looks like i miss something, or my configuration is buggy ?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    What version of the package are you using? Try updating to 1.4.4. If it's not visible in the package manager you can edit the manifest.json file in the package folder.
     
  5. wingeisoftware

    wingeisoftware

    Joined:
    Jun 15, 2021
    Posts:
    6
    i'm already on 1.4.4 for localization package.
    addressable package (previously installed) is in version 1.21.17
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    Which async event is not being fired?
    anAssetReference? The error you are getting is caused by calling WaitForCompletion inside of an addressables callback. If it's not being triggered by the completed event in the code you showed then it must be coming from another part. Do you have any other addressables loading?
     
  7. wingeisoftware

    wingeisoftware

    Joined:
    Jun 15, 2021
    Posts:
    6
    I tried a simple case where i load a LocalizedString which is directly associated to the same Gameobject.

    The sync and async both work well on editor, but that never worked from a build. I'm giving up as i already spent a lot of hours into this, reinstalling, reconfiguring, experimenting. My needs being simple, i'll make a custom system.

    Anyway, thanks for your help Karl !
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    Did you build the addressables data for the player?
    https://docs.unity3d.com/Packages/c...ariants.html#preview-and-configure-your-build

    Can you share the project so I can see whats going wrong?