(Case 1368143) LocalizationSettings.GetSelectedLocale() causes NullReferenceException

Unity 2019.4.20f1, Addressables 1.18.13, Localization 1.0.0-pre.10.

Calling LocalizationSettings.GetSelectedLocale() at some early points in the game, causes the following exception:

NullReferenceException: Object reference not set to an instance of an object.

UnityEngine.AddressableAssets.ResourceProviders.ContentCatalogProvider+InternalOp+BundledCatalog.WaitForCompletion () (at <00000000000000000000000000000000>:0)
UnityEngine.AddressableAssets.ResourceProviders.ContentCatalogProvider+InternalOp.WaitForCompletionCallback () (at <00000000000000000000000000000000>:0)
System.Func`1[TResult].Invoke () (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].WaitForCompletion () (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject].op_Implicit (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject] obj) (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.ChainOperation`2[TObject,TObjectDependency].InvokeWaitForCompletion () (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].WaitForCompletion () (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject].op_Implicit (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject] obj) (at <00000000000000000000000000000000>:0)
UnityEngine.AddressableAssets.Initialization.InitializationOperation.InvokeWaitForCompletion () (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].WaitForCompletion () (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle.set_IsWaitingForCompletion (System.Boolean value) (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.ChainOperationTypelessDepedency`1[TObject].InvokeWaitForCompletion () (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].WaitForCompletion () (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle.set_IsWaitingForCompletion (System.Boolean value) (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.ChainOperationTypelessDepedency`1[TObject].InvokeWaitForCompletion () (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].WaitForCompletion () (at <00000000000000000000000000000000>:0)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject].op_Implicit (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject] obj) (at <00000000000000000000000000000000>:0)
UnityEngine.Localization.Settings.LocalizationSettings.GetSelectedLocale () (at <00000000000000000000000000000000>:0)

The game code that caused it looks like this:

[RuntimeInitializeOnLoadMethod]
static void RuntimeInitializeMethod()
{
    var go = new GameObject();
    go.AddComponent<MyBehaviour>();
}

class MyBehaviour : MonoBehaviour
{
    void Start()
    {
        var locale = LocalizationSettings.SelectedLocale;
        if (locale == null)
            Debug.Log("locale is null");
    } 
}

I would find it more useful when LocalizationSettings.SelectedLocale returns null instead of crashing the app.

1 Like

Could you please file a bug report?

Thank you for the reply. Here is a test project to reproduce the problem:
(Case 1368143) 2019.4: LocalizationSettings.GetSelectedLocale() causes NullReferenceException

1 Like

QA was able to reproduce the issue, thumbs up!

1 Like

Hey.
I have taken a look at the bug report.
SelectedLocale itself does not produce the error, its coming deep from within Addressables.
The reason seems to be because the build and load paths are not set for the Default Local Group
7574449--938233--upload_2021-10-15_12-8-2.png

Changing them to this fixed it:

Im not sure if you wanted us to prevent exceptions from being thrown by SelectedLocale?
We could catch them but I dont think it would help much and there are many other API calls that can also throw exceptions from Addressables.
I will look at adding some tests to our analyzers to look for this path issue, it seems to be one of the main issues breaking projects upgrading to 1.0.0. The Addressables team confirmed there is a known issue with the build and load paths getting corrupted due to some serialization changes. They will have a fix in a update.

Edit: I noticed the Log Runtime Exceptions flag is enabled which should prevent exceptions being thrown. So this could be an Addressables bug. Ill speak to the team.

1 Like

Thank you for the reply.

I think what you found is another problem, but not the issue I initially reported in this thread.

The reason why I believe that, is the problem you pointed out with the Build/Load Path is a regression in Addressables 1.19.x (which I did report here ), but I submitted the Localization bug-report with Addressables 1.18.13.

I suggest you reproduce the problem using the attached project with the same Unity and packages versions I used to submit the bug-report before updating.

Hmm seems like QA upgraded the project I had.
I took a look at the original project that was submitted.

Theres a few different issues depending on the state.

The first one is System.Exception: Invalid path in TextDataProvider : /StreamingAssets/aa/settings.json'.. This is because the Addressable assets have not been built.

After building the next issue is key exception for Locale.
This is an old bug. If you added a Locale and no AddressableAsset settings existed then we would create one, setup the labels and assets etc. However the Locale label was being lost during this process which would cause it to not be shown here:

This is fixed now and can also be fixed by the Addressable analyzers.
7574653--938314--upload_2021-10-15_13-36-26.png

And finally there were several issues with our implementation of WaitForCompletion which we have fixed in 1.0.0 so this may also cause issues.

Hi,
Apologies for reviving an older thread, but we’ve just run into what appears to be the same underlying issue initially reported here.
I just wanted to check in and see if I’m missing anything obvious here. Any other ideas on what may cause this issue to occur?

Stacktrace below:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.AddressableAssets.ResourceProviders.ContentCatalogProvider+InternalOp+BundledCatalog.WaitForCompletion () [0x00001] in C:\jenkins\workspace\proj\Library\PackageCache\com.unity.addressables@1.20.3\Runtime\ResourceProviders\ContentCatalogProvider.cs:328
UnityEngine.AddressableAssets.ResourceProviders.ContentCatalogProvider+InternalOp.WaitForCompletionCallback () [0x00020] in C:\jenkins\workspace\proj\Library\PackageCache\com.unity.addressables@1.20.3\Runtime\ResourceProviders\ContentCatalogProvider.cs:116
UnityEngine.ResourceManagement.AsyncOperations.ProviderOperation`1[TObject].InvokeWaitForCompletion () [0x00086] in C:\jenkins\workspace\proj\Library\PackageCache\com.unity.addressables@1.20.3\Runtime\ResourceManager\AsyncOperations\ProviderOperation.cs:74
  • We are not using the localization package (but I see in the replies above this issue was confirmed to be an addressables error).
  • We are using addressables package version 1.20.3
  • All our bundles are local, we don’t use remote bundles at all.
  • I’ve verified all groups have their build & load paths correctly set as local.

I would try the addressables forum. Unity Engine - Unity Discussions
Im not aware of any issues to cause this but the Addressables team may be.