Setting localization language via script made the dialogue manager to stop working

Announcements, support questions, and discussion for the Dialogue System.
farazk86
Posts: 26
Joined: Sun Feb 26, 2023 9:13 am

Setting localization language via script made the dialogue manager to stop working

Post by farazk86 »

Hi,

I wrote all my text in English in the conversations tab of Dialogue Manager. I then exported that to my selected languages using the export option outlined here: https://www.pixelcrushers.com/dialogue_ ... ation.html

I added localized text to all the files and then imported them back.

This worked and I can now see localized versions of the conversation for each entry - great success so far..

Now I have a main menu button to select the language for the game, when the flag of that language is clicked it changes the language using

Code: Select all

DialogueManager.SetLanguage(language-code);
But after this, the dialogue window does not show up when I click on the button that calls:

Code: Select all

DialogueManager.StartConversation(nextAttackableScene);
Before the localization, this would bring up the dialogue canvas and the dialogue text would start, now nothing happens, no error shows up either.

Thank you
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Setting localization language via script made the dialogue manager to stop working

Post by Tony Li »

Hi,

Localization shouldn't affect whether the conversation starts or not.

Try temporarily setting the Dialogue Manager's Other Settings > Debug Level to Info so you can trace through what's going on. For more info on using Debug Level = Info, please see the Logging & Debugging Tutorial:

farazk86
Posts: 26
Joined: Sun Feb 26, 2023 9:13 am

Re: Setting localization language via script made the dialogue manager to stop working

Post by farazk86 »

Thanks for the response Tony, but it seemed to have fixed itself after a Unity editor restart :)

The dialogue canvas is now showing but the localized text is still not picked up.

The translations are properly imported as can be seen:
image_2023-11-18_204548173.png
image_2023-11-18_204548173.png (30.58 KiB) Viewed 2853 times
I change the dialogue text using:

Code: Select all

DialogueManager.SetLanguage("es");
But the English text is still loaded.

I am using a different asset for localizing the UI, and that changes but in the same function call I am also requesting the language change of DialogueManager.

I am changing the language in the main menu scene and the dialogue canvas is in a different scene, does this matter? Do I have to set the language in every scene where dialogue canvas exists?

Thanks
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Setting localization language via script made the dialogue manager to stop working

Post by Tony Li »

Hi,

No, you only need to change it once. Does your Dialogue Manager survive scene changes? This is the default and recommended behavior, but it's possible to change this in the Dialogue Manager's Other Settings section.
farazk86
Posts: 26
Joined: Sun Feb 26, 2023 9:13 am

Re: Setting localization language via script made the dialogue manager to stop working

Post by farazk86 »

My dialogue manager does not exist in the scene in which the localization menu exists.

Dialogue Manager only exists in a single scene where all the story telling happens. Do I have to have the dialogue manager present in the scene for this setting to take effect?
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Setting localization language via script made the dialogue manager to stop working

Post by Tony Li »

Hi,

Yes. The Dialogue Manager manages all Dialogue System activity, including calls to DialogueManager.SetLanguage().
farazk86
Posts: 26
Joined: Sun Feb 26, 2023 9:13 am

Re: Setting localization language via script made the dialogue manager to stop working

Post by farazk86 »

Right, understood. I may have missed that in the documentation. Apologies.

Does it have to be the same instance as in should I add a script for DontDestroyOnLoad() on it? I mean does it have to persist through all scenes? as I only have the dialogue manager in one scene, I dont want it to persist in every scene.

I added the dialogue manager prefab in my Main Menu where the localization setting is and set the different language (this is without persistent component) and when I entered the map scene the language was not changed.
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Setting localization language via script made the dialogue manager to stop working

Post by Tony Li »

If you put the Dialogue Manager in your main menu scene and keep its Other Settings > Don't Destroy On Load checkbox ticked, does it work correctly?
farazk86
Posts: 26
Joined: Sun Feb 26, 2023 9:13 am

Re: Setting localization language via script made the dialogue manager to stop working

Post by farazk86 »

yes it works now. The dialogue language changed. Thanks :)

But this is not ideal for me, as I scene dependent events in my dialogue manager and would prefer the old one to persist. Also in some cutscene scenes I have a different dialogue manager with different settings.

Would it be wise to set the language selection to a playerpref in the main menu where the language is changed and then in every scene where I have a dialogue manager I can read the language setting from the player pref and load it there in Awake()?

Or would there be a better way to go about this?

Thanks
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Setting localization language via script made the dialogue manager to stop working

Post by Tony Li »

There are a few ways you can do this.

You could allow the main menu scene's Dialogue Manager to persist across all scenes. This won't affect scene-dependent events. (I'm assuming you're using one database, or loading the extra databases using an Extra Databases component.) Then you don't have to worry about it.

Or you can use a different Dialogue Manager in each scene that only survives in that scene. Add a script with an Awake() method like this:

Code: Select all

DialogueManager.SetLanguage(PlayerPrefs.GetString("Language"));
When you set a language, the Dialogue Manager will store that language in the "Language" PlayerPrefs key, so you can use the code above to set it again.
Post Reply