Hi Chris,
I have an AC menu that pauses gameplay. While it is open, I run a Dialogue: Play speech action for the Player.
I enable and disable a helper script through AC’s Object: Call action like this:
EnablePausedSpeechSubtitles
Dialogue: Play speech
DisablePausedSpeechSubtitles
The speech was getting stuck because Time.timeScale is 0, so while enabled the script sets the currently active Speech to use unscaled time:
Speech speech = KickStarter.dialog.GetLatestSpeech();
if (speech != null)
{
speech.useUnscaledTime = true;
}
That lets the speech complete correctly.
However, the normal Subtitle menu does not appear when speech starts after the game is already paused.
I previously tried manually using SetSpeech on the normal Subtitle menu, but that caused old Player lines to remain displayed later, so I removed that approach.
My current test script does only two things while enabled:
speech.useUnscaledTime = true;
subtitlesMenu.TurnOn(false);
The TurnOn call is only made while the game is paused and speech is actively playing. I do not call SetSpeech, ClearSpeech, TurnOff, ForceOff, or assign any speech reference manually.
This appears to work correctly so far. Is calling TurnOn(false) on the existing automatic Subtitle menu in this situation a valid/safe approach, or is there a better AC-supported way to allow dialogue speech to work during an opened menu with paused enabled.
using UnityEngine;
using AC;
public class ACPausedSpeechSubtitleMenu : MonoBehaviour
{
[Header("Disabled by default")]
[SerializeField] private bool enablePausedSpeechSubtitles = false;
[Header("AC Subtitle menu name")]
[SerializeField] private string subtitlesMenuName = "Subtitles";
private Menu subtitlesMenu;
private void Update()
{
if (!enablePausedSpeechSubtitles || KickStarter.dialog == null)
{
return;
}
Speech speech = KickStarter.dialog.GetLatestSpeech();
if (speech != null)
{
speech.useUnscaledTime = true;
}
}
private void LateUpdate()
{
if (!enablePausedSpeechSubtitles ||
KickStarter.dialog == null ||
KickStarter.stateHandler == null)
{
return;
}
if (KickStarter.stateHandler.gameState != GameState.Paused ||
!KickStarter.dialog.IsAnySpeechPlaying())
{
return;
}
if (subtitlesMenu == null)
{
subtitlesMenu = PlayerMenus.GetMenuWithName(subtitlesMenuName);
}
if (subtitlesMenu == null)
{
Debug.LogWarning(
"ACPausedSpeechSubtitleMenu: Could not find AC menu named \"" +
subtitlesMenuName + "\"."
);
return;
}
subtitlesMenu.TurnOn(false);
}
public void EnablePausedSpeechSubtitles()
{
enablePausedSpeechSubtitles = true;
}
public void DisablePausedSpeechSubtitles()
{
enablePausedSpeechSubtitles = false;
}
}
Thanks.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
I'd say that should be fine. You should be able to do away with the Update/LateUpdate loops by hooking into the OnStartSpeech custom event to turn the Menu on at the time the speech begins, but I don't see anything fundamentally wrong with your approach.