I found that when using Unity UI for subtitle menu, and use AC.EventManager.OnStartSpeech += GetSpeech; in OnEnable() to get the dialog to display in the Unity UI, the AC.EventManager.OnStartSpeech event would happens before the subtitle menu canvas game object OnEnable() function.
So that if AC.EventManager.OnStartSpeech -= GetSpeech; is used in OnDisable(), the next dialog cannot be parsed by GetSpeech because AC.EventManager.OnStartSpeech += GetSpeech; is executed after the AC.EventManager.OnStartSpeech for the dialog.
Anyone else encountered this? How could this be solved?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
That's the intended order - the menu will turn on as a result of speech beginning, rather than the other way around.
I'm assuming that this is for a script attached to the UI prefab, and that your Menu's Appear type is set to When Speech Plays.
The Menu will only turn on when shown for a speech line. You should be able to perform what you need in OnEnable / OnDisable directly, without the need for events.
If you have Duplicate for each line? checked, you can then extract the Speech line that the menu is turning on for with:
Otherwise, you can get the latest speech line with:
I'm only talking generally here, though. If you need more specific advice, I'll need more details and context.
Thanks. This solved the "OnStartSpeech before OnEnable()" issue.
However, for menus that are NOT Duplicate for each line?, I still need a way to catch the 2nd dialog onwards, as the function inside OnEnable() won't be called again. I tried the **OnStartSpeech ** event but the the same error occured as before. How may I catch those dialog?
Hooking into the OnMenuTurnOn event should allow you to do that.
Do you mean AC.EventManager.OnMenuTurnOn += TriggerGetSpeech;?
But my menu is set to NOT Duplicate for each line, so it only catches the first line after the menu is turned on. I need to find a way to tell the menu to display the latest speech everytime a new speech happens.
I solved it by using both AC.EventManager.OnStartSpeech += GetSpeech; and Speech speech = KickStarter.dialog.GetLatestSpeech (); in OnEnable(). The former is for getting the 2nd speech onward after a menu turned on; while the later is for getting the 1st speech.
Please tell me if there is a more efficient way.
OnMenuTurnOn will trigger each time the menu is turned on - regardless of whether it is duplicated for each line:
But does OnMenuTurnOn only triggered at the occasion when the menu is turned on? So when there is a series of dialogs in the same Actionlist, it would only GetLatestSpeech () for the first dialog, but not the following dialogs because the menu has already turned on before?
If your speech Actions are chained together without delays, then yes - it'll turn on for the first and remain on for others.
Hook into OnStartSpeech as you were as well - you can then redirect both events to the same function, i.e.: