LocalizeAudioClipBehaviour Scripting syntax help needed

Unity 2019.3. I’m a beginner.
Can’t find any example or help on the syntax to change the “Localized Asset Reference” (TabAssets/…) in a “Localize Audio Clip” Compontent from a script.
(I made it to change the localisation of a text per Script, I guessed the Audio is similar.)
Set Up:
Asset Table is filled. I have an audio Source, added a Localize Audio Clip component to it. Wrote a script, attatched it to the Audio Source.
Now I need to pass one of my Keys of my Asset Table as a string to that component to play the localized audio.
My very short script:

using UnityEngine;
using UnityEngine.Localization.Components;

public class AudioSubTitle : MonoBehaviour
{
public LocalizeAudioClipBehaviour subTitleAudio;

public void ShowText(string audioToPlay)
{
// here ist where i have no clue what to enter…
subTitleAudio. ? = audioToPlay;
}
}
Any help is appreciated…

There is a property called AssetReference, that will let you get the clip https://docs.unity3d.com/Packages/com.unity.localization@0.6/api/UnityEngine.Localization.LocalizedAssetReference.html

thank you for the answer, but the link doesn’t work… (page seems to be missing)

Sorry try this Class LocalizedAssetBehaviour<TObject, TReference> | Localization | 0.6.1-preview

That link works, but I’m getting this error when saving this:
“subTitleAudio.AssetReference = audioToPlay;”
error CS0029: Cannot implicitly convert type ‘string’ to ‘UnityEngine.Localization.LocalizedAudioClip’
Maybe i didn’t desribe this clear enough or I did a mistake.
I don’t want to pass an Audioclip, but just the Key (“Mom_Nerv_1”) i have in the Asset Tables like in the example below.

(Like it works with Localize String with this: “public LocalizeStringBehaviour subTitel;” and “subTitel.StringReference.TableEntryReference = textToShow;” I just need to pass the key to the “String Reference”, “Entry Name” and don’t need to worry about the rest.)

Here the Compontent attachted to the AudioSource:
5889608--627779--upload_2020-5-23_16-24-45.png

Here are the keys in my Asset Table (Right now only the German ones do have an audio file linked):

5889608--627764--upload_2020-5-23_16-16-25.png

There should be a TableEntryReference property you can assign the entry name to. It won’t auto update when the value changes though. That’s something we have added in the next release.

I’m replying on my phone so I don’t have source code in front of me at the moment.

1 Like

Works! :slight_smile:
Thanks for the fast answers!
You mean that the auto Update is not working for clips already playing? Because it plays the other audio clip i’m assigning. (The last clip finnished playing before assigning the new one).

In case someone else needs it, here is my code:

using UnityEngine.Localization.Components;

public class AudioSubTitle : MonoBehaviour
{
public LocalizeAudioClipBehaviour subTitleAudio;

public void PlayKey(string audioToPlay)
{
subTitleAudio.AssetReference.TableEntryReference = audioToPlay;
GetComponent().Play();
}
}

1 Like