Hello,
We're currently trying to tap into the capabilities of the speech event tokens and as far as we can tell we have set up everything correctly as per the documentation; however, no matter what we do we cannot get the OnSpeechToken event to ever trigger. Here is a snippet of how our code is setup:
**
using UnityEngine;
using AC;
public class SpeechTokenMonitor : MonoBehaviour
{
private void OnEnable()
{
KickStarter.dialog.SpeechEventTokenKeys = new string[1] { "test" };
EventManager.OnStopSpeech += OnStopSpeech;
EventManager.OnCompleteSpeechScroll += OnCompleteSpeechScroll;
EventManager.OnSpeechToken += OnSpeechToken;
}
private void OnDisable()
{
EventManager.OnStopSpeech -= OnStopSpeech;
EventManager.OnCompleteSpeechScroll -= OnCompleteSpeechScroll;
EventManager.OnSpeechToken -= OnSpeechToken;
}
private void OnCompleteSpeechScroll(Char speakingCharacter, string speechText, int lineID)
{
AC.ACDebug.Log($"Speech Line# {lineID} done for char: {speakingCharacter.name}");
}
private void OnStopSpeech(Char speakingCharacter)
{
}
private void OnSpeechToken(Char speaker, int lineID, string tokenKey, string tokenValue)
{
AC.ACDebug.Log("token found in speech");
if (tokenKey == "test")
{
AC.ACDebug.Log("expression token found");
}
}
}
**
We have this script hooked up to a UI prefab that gets dynamically loaded upon any dialogue speech occurring (ie our custom speech visual bubble hooked up via the Menu Manger / subitles sub menu)
Here is an example line of speech text we have setup in an Action List Asset / Dialogue PlaySpeech action list event
[test:neutral]Hello test token world
Given this setup, and given that the script defined above is hooked up to our UI prefab object that gets dynamically loaded we would expect that the OnSpeechToken function would trigger when the dynamically loaded object is created. And we would also expect when the piece of speech listed above plays that the [test:neutral] would be recognized. However, not only does the OnSpeechToken event not fire off on the dynamically loaded object but the token isn't removed from the dialogue and thus it all shows up when the speech plays
Is there something special we have to do when registering the tokens with KickStarter.dialog.SpeechEventTokenKeys
Should we do that separately in some form of static scene object ahead of time as opposed to setting this field on an object that is getting dynamically loaded? We're really not sure what is going wrong
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
If it's part of the UI prefab, then the events will register at the same time the menu is displayed. Though, I should imagine the code you've got should work. Do none of the Debug.Log statements appear?
I'll attempt a recreation. For accuracy, can you share your AC/Unity versions, as well as screenshots of your Subtitle menu's properties, and Speech Manager values?
None of the debug statements appear at all. And when my speech text action list plays in game, ie my Dialogue Play Speech event with line text value of:
[test:neutral]Hello test token world
It just shows the whole line of text as show above (i.e. it didn't even register that I put in a text token so the text token also showed up as part of the in game text)
Here is that version info:
Unity Version: 2020.1.3f1
AC Version: v1.72.4
And my failed attempt at attaching screen shots (seems local image uploads isn't supported here):
Hopefully these screenshot links work:
https://drive.google.com/file/d/1ZHwYbFf7mjAUMhQ2NLiUGcTxQ-PWukeR/view?usp=sharing
https://drive.google.com/file/d/1EbgmfWQiv1I1hyhPGNqWOaVSJz2t5G-x/view?usp=sharing
https://drive.google.com/file/d/1kAAzIlZzQNs3rxkrM8Xe3QgLUYL5IY3L/view?usp=sharing
https://drive.google.com/file/d/1w7Crk442Yd5les_Ayu2Vh3zLz9ruF761/view?usp=sharing
Thanks for the details.
The issue is that you're defining your SpeechEventTokenKeys when the Menu is turned on - which occurs as a result of the Speech beginning, meaning the tokens have already been processed by that point.
What you'll need to do is move this line to the Start function of a script present in your scene, so that it runs before any speech line is played, i.e.:
The rest of your script, however, should be fine as-is.
Thanks, looks like that was the trick.