Search Unity

Question Release not required StringTable assets

Discussion in 'Localization Tools' started by EduardDraude, Dec 7, 2020.

  1. EduardDraude

    EduardDraude

    Joined:
    Mar 8, 2019
    Posts:
    60
    Hey!

    I use the Addressables system to fetch some content package, which also contain string tabels (one for each locale and the shared data asset). At some point the user is able to delete these packages. Currently, the cache cant be deleted for this addressable bundle, because the string table is still be loaded, when I accessed some table at some point.

    So how would I release/unload all string tables which are somehow accociated to my asset bundles?
    Is there an API methos, which I could not find to to such things?

    And also when I change the language, why are the tables from the previous language not released/unloaded?
     
    Last edited: Dec 7, 2020
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    We have done a lot of improvements to the Addressable handling in the next version which may fix some of these issues. Could you file a bug report so we can make sure?
     
    EduardDraude likes this.
  3. EduardDraude

    EduardDraude

    Joined:
    Mar 8, 2019
    Posts:
    60
    Not sure if this is a bug. I just want to release the loaded string tables (which were loaded via the addressables system) on demand. Somehow I even cant unload the string tables with the addressables API. Or I just dont know what to pass as parameter in
    Addressables.Release(...)
    ...
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    Could you file a bug ?
     
    sniffle63 likes this.
  5. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365

    Releasing the handler works for me, this is how im doing it.


    Code (CSharp):
    1. public class StringRefTest : MonoBehaviour
    2. {
    3.     public LocalizedString stringRef;
    4.     public TextMeshProUGUI text;
    5.     public string dynamicString;
    6.  
    7.     private AsyncOperationHandle<string> _stringHandler;
    8.  
    9.  
    10.     // Start is called before the first frame update
    11.     void OnEnable()
    12.     {
    13.         stringRef.Arguments = new object[] {this};
    14.         StartCoroutine(SetString());
    15.         stringRef.StringChanged += StringRefOnStringChanged;
    16.     }
    17.  
    18.  
    19.     private void OnDisable()
    20.     {
    21.         stringRef.StringChanged -= StringRefOnStringChanged;
    22.         Addressables.Release(_stringHandler);
    23.     }
    24.  
    25.  
    26.     private IEnumerator SetString()
    27.     {
    28.         _stringHandler = stringRef.GetLocalizedString();
    29.         yield return _stringHandler;
    30.         text.SetText(_stringHandler.Result);
    31.     }
    32.  
    33.  
    34.     private void StringRefOnStringChanged(string value)
    35.     {
    36.         text.SetText(value);
    37.     }
    38. }
    Altho I'm curious if this is recommended.


    Also on a side note, the documents are wrong for the LocalizedString.Arguments, you can not use Add because it's an array, not a list.
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    Yes, this is the correct way. You should call Aquire if you plan to hold onto the AsyncOperationHandle and Release when finished. In 0.10 we have fixed a lot of issues where we do not do this and we will automatically release operations in the next frame so they can be reused(if you don't call Aquire to keep hold of it).

    So in your example calling Release will actually cause an error because the string will be released again by us(in 0.10).
    In your above example, you use the string as soon as you get it and do not need to hold onto the operation after that. So you can remove the Addressables.Release as this will be handled correctly in the next release.

    So, as a rule in 0.10.0-preview, you should only call Release if you have at some point called Aquire on the operation.

    Oh yes we changed it. Which docs are you referring to?
     
  7. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    Awesome thanks a lot for the reply!

    Might have been looking at docs for an older version, I cant seem to find it today!
     
    karl_jones likes this.