Hello,
I have a button which I want to deactivate its interaction when subtitle menu is launched.
So I created a custom action that changes interaction of the button (true/false) and I run it on "ActionList when turn on" and "ActionList when turn off" of the menu.
The first time the subtitle menu appears works. But when I press next and goes to the second Dialogue it runs the "ActionList when turn off" but doesn't re-run the "ActionList when turn on" and the button stays activated.
How exactly the dialogue system works?
My setup is Display Subtitles forever until user Skips it and I use a button with Input Axis : SkipSpeech
Is there any other way to disable interactivity of a button when certain Menus are opened?
Thank you
Comments
There are alternatives to the "When turn on/off" ActionLists however - you can use events, which - since you're using a custom Action - would probably be the better choice anyway.
See the Manual's "Custom events" chapter. There's two that you can try:
OnMenuTurnOn (Menu menu, bool isInstant);
OnStartSpeech (AC.Char speaker, string speechText, int lineID);
If you used the OnMenuTurnOn event, you can just check for the menu's title, i.e.:
if (menu.title == "Subtitles")
{
// Do something
}
A tutorial for using the OnStartSpeech event can be found here, but the principle applies to all events.
Question : when you add several Dialogue Play Speech actions in sequence on an ActionList, those actions work continuously? I mean.. the first Dialogue opens the Subtitle Menu and the others follow without closing it? or each action opens / close the menu? The "ActionList when turn off" option runs for each one or only for the last one?
I'm gonna try thought the OnStartSpeech and see if it works. Thank you!
From the Logs when I press next and runs the second action Play Speech from what I see is that first runs the OnEnable for the second Subtitle Menu and then the OnDisable of the first Subtitle Menu which also run 12 times.
It's a simple ActionList where it has 2 Dialogue : Play Speech actions (narration)
and on my setup I have " Display Subtitles forever until user Skips"
The button I use to skip is an AC.Button with Input Axis : SkipSpeech
this is the code I have attached on my Unity UI Button. (Frame is the name of the Unity UI button which I want to deactivate on speeches.)
private void OnEnable()
{
EventManager.OnMenuTurnOn += OnMenuTurnOn;
EventManager.OnMenuTurnOff += OnMenuTurnOff;
}
private void OnDisable()
{
EventManager.OnMenuTurnOn -= OnMenuTurnOn;
EventManager.OnMenuTurnOff -= OnMenuTurnOff;
}
void OnMenuTurnOn(AC.Menu menu, bool isInstant)
{
Debug.Log(menu.title);
if (menu.title == "Subtitles" || menu.title == "Subtitles NPCs" || menu.title == "SubtitlesNarattion")
{
Frame.interactable = false;
Debug.Log("button Deactivated");
}
}
void OnMenuTurnOff(Menu menu, bool isInstant)
{
Debug.Log(menu.title);
if (menu.title == "Subtitles" || menu.title == "Subtitles NPCs" || menu.title == "SubtitlesNarattion")
{
Frame.interactable = true;
Debug.Log("button Activated");
}
}
EDIT : After some research I found out that at PlayersMenu.cs the Line 1407 : menu.TurnOff (true);
runs all the time and when you click Skip on a dialogue it runs 12 times and triggers the OnDisable that many times and all these happens after the OnEnable of the next dialogue
The "Play in background?" option in the Dialogue: Play speech Action determines whether they are run instantly or not.
Have you checked Duplicate for each line? in the Subtitles menu's properties? If not, does doing so make a difference? That option causes each line to have its own instance of the menu.
It won't, however, prevent OnMenuTurnOn from calling after OnMenuTurnOff if you are using duplicate menus.
What you can try instead is to simply read whether or not any speech is actually playing at all:
void Update ()
{
Frame.interactable = !AC.KickStarter.dialog.IsAnySpeechPlaying ();
}