Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple LocalizationSettings assets created if Library folder is deleted #20

Open
iMobCoding opened this issue Mar 23, 2023 · 12 comments

Comments

@iMobCoding
Copy link

So try closing the Unity project. Then delete the Library folder and open the project again. Observe multiple LocalizationSettings assets created, in my case it's always original LocalizationSettings + 17 more.

Also there are some errors like:

  • [Worker0] CreateSerializedAsset is not supported while importing out-of-process

  • [Worker0] UnityException: Creating asset at path Assets/Resources/LocalizationSettings 18.asset failed.

This happens in Unity v2021.3.21

The problem is in line 66 of the LocalizationSettings.cs because Resources.Load returns null while importing assets. So then it goes to the CreateSettingsAndSave which saves new assets after delay multiple times...

@iMobCoding
Copy link
Author

iMobCoding commented Mar 24, 2023

Looks pretty simple to fix by inserting this check in SaveAsset method:

var assetPath = "Assets/Resources/" + AssetName + ".asset";
if (!string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(assetPath)))
    return;

// rest of the code

But I'd still investigate why FindByResources() returns null

@ibrahimpenekli
Copy link
Owner

Looks pretty simple to fix by inserting this check in SaveAsset method:

var assetPath = "Assets/Resources/" + AssetName + ".asset";

if (!string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(assetPath)))

    return;



// rest of the code

But I'd still investigate why FindByResources() returns null

Hi @iMobCoding ,

Thanks for addressing the issue.
You can make a PR for the bug fix.

@iMobCoding
Copy link
Author

Yes but unfortunately that's a bad way to fix this. I have to find a reason why this is happening. I've discovered that in the empty project (with only localization installed) this doesn't happen. In my project few prefab variants are causing this (that's why it makes 18 settings files for me). I'll keep you posted and if I find it I'll make a PR

@iMobCoding
Copy link
Author

Ok upon further investigation I found this Unity Issue:
https://issuetracker.unity3d.com/issues/asset-will-return-null-even-if-that-asset-exists-when-calling-resources-dot-load-but-only-for-the-first-time

The problem is this according to their explanation:
Non scripts can not reliably be loaded from InitializeOnLoad static constructors

You won't experience this bug in normal circumstances. For me it happened with Odin and Localized Texts inside prefab variants. Every time Library got deleted, new LocalizedSettings were created as many times as there are Localized Texts in prefab variants...

This PR fixes it

@iMobCoding
Copy link
Author

@ibrahimpenekli Any news about the PR?

@ibrahimpenekli
Copy link
Owner

Sorry I was busy I couldn't look into it. On a second thought, this solution will break backward compatibility. LocalizationSettings asset is not forced to be in a specific location.
Give me some time to think about another solution or I will merge this and release it with a new version. Thanks.

@ibrahimpenekli
Copy link
Owner

Hi @iMobCoding

I used this Unity function to get active settings:

UnityEditor.EditorBuildSettings.TryGetConfigObject(ConfigName, out LocalizationSettings settings);

So, the settings asset does not need to be located in a specific folder or in the Resources folder.

You can use this bugfix with the 2.2.3 version.
Thanks for your help!

@iMobCoding
Copy link
Author

iMobCoding commented Apr 29, 2023

Hi @ibrahimpenekli

Upon further testing of the v2.2.3 I found that it doesn't create new LocalizationSettings indeed, but it bombards the log with multiple worker warnings and errors.

image

Log.txt

image

@ibrahimpenekli
Copy link
Owner

That is really strange behaviour.
Which Unity version do you use?
And how to reproduce this issue? Because deleting Library folder does not generate these errors for me.

@iMobCoding
Copy link
Author

It's the 2021.3.24 Unity, but it happens with lower versions too. I think it doesn't happen with simple localizations but if used inside prefab or prefab variant then it happens. I'll prepare a small reproducible project and send it to you here

@iMobCoding
Copy link
Author

iMobCoding commented Apr 30, 2023

Ok here is the reproducible project. Once you delete the Library and open the project, click once on Localization Settings and then on Panel - Variant prefab. You'll see the worker errors. You have to do it manually in this case as those prefabs aren't referenced in any scripts. In my project, several assets are referenced so when you delete the library folder everything happens automatically on project opening... Let me know if you can reproduce the issue

image

Localization Test.zip

Edit: you don't have to delete the whole Library folder every time, delete just the ArtifactDB file inside the Library folder and open the project again, it's faster for testing

@ibrahimpenekli ibrahimpenekli reopened this May 2, 2023
@ibrahimpenekli
Copy link
Owner

Thanks for the project and detailed explanation. I'll look into that as soon as possible when I have time.

Repository owner deleted a comment from chasedson Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants