Continue button and playing audio
Continue button and playing audio
Hi Tony,
Hope you are doing well!
I'm having some trouble with how the continue button interacts with the Audio() sequence.
Using Textline with typewriter effects & a continue button.
I want to play a sound effect at the end of the dialogue:
{{default}}->Message(playsound);
Audio(audioName)@Message(playsound);
This works fine until the player clicks the continue button while typewriter is still running. First click stops the typewriter effect, but doesn't immediately move to play the audio. And second click loads the next dialogue entry, so the audio doesn't get played.
Is there a way to have the audio play immediately after the first continue button is clicked?
Cheers,
Amy
Hope you are doing well!
I'm having some trouble with how the continue button interacts with the Audio() sequence.
Using Textline with typewriter effects & a continue button.
I want to play a sound effect at the end of the dialogue:
{{default}}->Message(playsound);
Audio(audioName)@Message(playsound);
This works fine until the player clicks the continue button while typewriter is still running. First click stops the typewriter effect, but doesn't immediately move to play the audio. And second click loads the next dialogue entry, so the audio doesn't get played.
Is there a way to have the audio play immediately after the first continue button is clicked?
Cheers,
Amy
Re: Continue button and playing audio
Hi Amy,
I recommend setting it up like this:
1. Add this script to the subtitle text GameObject:
2. Configure the typewriter effect's OnEnd() method to call the script's SequencerMessageSender.SendSequencerMessage. In the text field, enter "DoneTyping".
3. Set the dialogue entry's Sequence to:
Note: The Audio() command starts the audio and then forgets about it. If you want the audio to stop when the player continues the conversation, use AudioWait().
I recommend setting it up like this:
1. Add this script to the subtitle text GameObject:
SequencerMessageSender.cs
Code: Select all
using UnityEngine;
public class SequencerMessageSender : MonoBehaviour
{
public void SendSequencerMessage(string message)
{
PixelCrushers.DialogueSystem.Sequencer.Message(message);
}
}
3. Set the dialogue entry's Sequence to:
Code: Select all
{{default}};
Audio(audioName)@Message(DoneTyping)
Re: Continue button and playing audio
This worked perfectly, thanks Tony!
A follow up question (just curious not a necessity), is there a way to trigger audio or other sequences when the dialogue reaches a certain word? Instead of at the start, end, or with a set delay.
Also was the issue with Enhanced Scroller resolved? Haven't checked back in a while
A follow up question (just curious not a necessity), is there a way to trigger audio or other sequences when the dialogue reaches a certain word? Instead of at the start, end, or with a set delay.
Also was the issue with Enhanced Scroller resolved? Haven't checked back in a while
Re: Continue button and playing audio
Nothing is built in for that. You'd have to do some custom coding.
Not yet. I'm traveling this week and not able to do much development work until Monday.
Re: Continue button and playing audio
Hi Tony!
So I've encountered a problem with this solution from a while back:
I noticed this happens when:
1. Subtitle Settings > Continue Button is set to Optional (conversation is auto-playing)
2. The node directly before that has no sequence in it and perhaps it's getting triggered by the DoneTyping message from that previous node.
At the moment I don't have any idea how to resolve this, so hoping for your input
Cheers,
Amy
So I've encountered a problem with this solution from a while back:
Most of the time it works well, however some cases my audio will play at the start of the node instead of at the end of typewriter effect when DoneTyping message is sent.Tony Li wrote: ↑Wed Jul 10, 2019 2:28 pm Hi Amy,
I recommend setting it up like this:
1. Add this script to the subtitle text GameObject:2. Configure the typewriter effect's OnEnd() method to call the script's SequencerMessageSender.SendSequencerMessage. In the text field, enter "DoneTyping".SequencerMessageSender.cs
Code: Select all
using UnityEngine; public class SequencerMessageSender : MonoBehaviour { public void SendSequencerMessage(string message) { PixelCrushers.DialogueSystem.Sequencer.Message(message); } }
3. Set the dialogue entry's Sequence to:Note: The Audio() command starts the audio and then forgets about it. If you want the audio to stop when the player continues the conversation, use AudioWait().Code: Select all
{{default}}; Audio(audioName)@Message(DoneTyping)
I noticed this happens when:
1. Subtitle Settings > Continue Button is set to Optional (conversation is auto-playing)
2. The node directly before that has no sequence in it and perhaps it's getting triggered by the DoneTyping message from that previous node.
At the moment I don't have any idea how to resolve this, so hoping for your input
Cheers,
Amy
Re: Continue button and playing audio
Hi Amy,
Do you want to always play the same audio clip every time the typewriter finishes?
If so, then instead of the sequence you could try this:
1. Add an Audio Source to the dialogue UI. Untick Loop and Play On Awake.
2. Configure the typewriter effect's OnEnd() event to call the Audio Source's AudioSource.PlayOneShot method. Assign the audio clip.
Do you want to always play the same audio clip every time the typewriter finishes?
If so, then instead of the sequence you could try this:
1. Add an Audio Source to the dialogue UI. Untick Loop and Play On Awake.
2. Configure the typewriter effect's OnEnd() event to call the Audio Source's AudioSource.PlayOneShot method. Assign the audio clip.
Re: Continue button and playing audio
No unfortunately I'm calling different audioclips with dialogue sequence. So sometimes some nodes won't be playing any audio.
Re: Continue button and playing audio
Okay, I'll give this a little thought and reply back later today.
Re: Continue button and playing audio
Thank you Tony
Re: Continue button and playing audio
The previous node's typewriter effect ends on the same frame that the new node starts. So it's possible that the new node will receive the "DoneTyping" message as you've described. Let's modify the approach.
Here's an example scene: AudioAtTypewriterEndExample_2019-08-07.unitypackage
It uses two small scripts:
It does not use the scripts in previous posts of this thread. You can remove those scripts from your project if you want.
Instead of this:
Use this:
The new sequencer command SetTypeEndAudio() queues an audio clip to play when the typewriter is done. It waits one frame to avoid the timing issue of the previous solution.
Then add the other script (TypeEndAudio) to the subtitle text GameObject, and configure the typewriter effect's OnEnd() to call TypeEndAudio.PlayAudioClip.
Here's an example scene: AudioAtTypewriterEndExample_2019-08-07.unitypackage
It uses two small scripts:
SequencerCommandSetTypeEndAudio.cs
Code: Select all
using UnityEngine;
using System.Collections;
namespace PixelCrushers.DialogueSystem.SequencerCommands
{
public class SequencerCommandSetTypeEndAudio : SequencerCommand
{
private IEnumerator Start()
{
yield return null; // Wait 1 frame for previous node's typewriter to finish.
var audioClip = DialogueManager.LoadAsset(GetParameter(0), typeof(AudioClip)) as AudioClip;
TypeEndAudio.audioClip = audioClip;
if (audioClip == null) Debug.LogWarning("Dialogue System: Sequencer: TypeEndAudio(" + GetParameters() + "): Audio clip not found in Resources or asset bundle.");
Stop();
}
}
}
TypeEndAudio.cs
Code: Select all
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class TypeEndAudio : MonoBehaviour
{
public static AudioClip audioClip = null;
public void PlayAudioClip()
{
if (audioClip != null)
{
GetComponent<AudioSource>().PlayOneShot(audioClip);
audioClip = null;
}
}
}
Instead of this:
Code: Select all
{{default}};
Audio(audioName)@Message(DoneTyping)
Code: Select all
{{default}};
SetTypeEndAudio(audioName)
Then add the other script (TypeEndAudio) to the subtitle text GameObject, and configure the typewriter effect's OnEnd() to call TypeEndAudio.PlayAudioClip.