Starting conversation/cutscene from script

Announcements, support questions, and discussion for the Dialogue System.
robloxillian
Posts: 27
Joined: Mon Sep 13, 2021 6:55 pm

Starting conversation/cutscene from script

Post by robloxillian »

I would like to play a cutscene when the player collides with an invisible trigger. I tried setting it up as a conversation and calling DialogueManager.StartConversation(). However, the game doesn't pause like it normally does when a conversation starts, and the player can still move around. I'm also not sure how to make that specific conversation un-skippable (i.e., clicking/pressing buttons does not advance the dialogue). I have tried:

- Calling DialogueManager.PauseGame() in the script before starting the conversation. This prevents the conversation from starting.
- Setting Time.timeScale = 0f before starting the conversation. This works, but the game doesn't unpause when the conversation is over.

I also want to make an NPC walk during the cutscene, but I haven't looked into this much yet. Is this the right overall strategy to do what I'm trying to do? In particular, is playing the cutscene via a conversation an intended workflow? If so, what step might I be missing compared to the steps that happen when I start a conversation using a Dialogue System Trigger and "start conversation"?
User avatar
Tony Li
Posts: 21961
Joined: Thu Jul 18, 2013 1:27 pm

Re: Starting conversation/cutscene from script

Post by Tony Li »

Hi,

There are a few ways to do this. Here are two good ways:

1. Use DialogueManager.StartConversation(), but specify the player GameObject so it will receive the "OnConversationStart" message. This assumes your player GameObject disables player control in OnConversationStart (e.g., with a Dialogue System Events component's OnConversationStart() UnityEvent). In the conversation, use sequencer commands to move the NPC, play voiceover, etc.

2. Or use a scrubbing cutscene editor such as Paradox Notion's SLATE or Unity's Timeline. Control the NPC's movement using the cutscene. Use the Dialogue System's actions/clips for that cutscene editor to play the conversation.

If your cutscene is very dialogue-heavy, I recommend #1. However, if there's lots of complex action and little dialogue, I recommend #2. You can also do a hybrid: Use #1, but use the SLATE() or Timeline() sequencer command in specific dialogue entry nodes to run cutscenes specific to that dialogue entry node.
robloxillian
Posts: 27
Joined: Mon Sep 13, 2021 6:55 pm

Re: Starting conversation/cutscene from script

Post by robloxillian »

Thank you. It looks like OnConversationStart() is always being sent when starting the dialogue via script-- it turns out setting TimeScale = 0f here works correctly, but for some reason setting TimeScale = 1f in OnConversationEnd() doesn't always work and sometimes the player remains unable to move. It seems like maybe it only works if the conversation has no event at the end or cutscene afterwards? Does that sound like something that I should expect? Let me know if I need to provide more information.
User avatar
Tony Li
Posts: 21961
Joined: Thu Jul 18, 2013 1:27 pm

Re: Starting conversation/cutscene from script

Post by Tony Li »

Can you confirm that the conversation is actually ending? Temporarily set the Dialogue Manager's Other Settings > Debug Level to Info. Then reproduce the issue. When the conversation ends, check the Console window for:

Dialogue System: Conversation ending.
robloxillian
Posts: 27
Joined: Mon Sep 13, 2021 6:55 pm

Re: Starting conversation/cutscene from script

Post by robloxillian »

I applied this setting and I do see "Dialogue System: Ending Conversation." I'm a bit puzzled, because my mental model of the steps that are happening makes the result seem impossible:

1. The conversation starts, which calls my OnConversationStart() callback. In this method, I set Time.timeScale = 0f.
2. A cutscene plays, prompted by a C# script called via an event at the end of the conversation.
3. In the script, I set Time.timeScale = 1f.

For some reason, if I take out the "Time.timeScale = 0f" in step 1, the player can move after the cutscene again. This means that this line is definitely the cause of the player's inability to move, and I have also confirmed that the timeScale immediately before the line is 1. However, "Time.timeScale = 1f" (which is being called afterwards) does not let the player move again.

Is it possible that time needs to be passing for some step in the process to take place, or that things aren't actually happening in the order the debug shows?
robloxillian
Posts: 27
Joined: Mon Sep 13, 2021 6:55 pm

Re: Starting conversation/cutscene from script

Post by robloxillian »

I did a bit more investigating and it turns out the problem was that Time.timeScale was getting set to 0 when I was pressing escape to advance the dialogue. I have a check for DialogueManager.IsConversationActive which normally prevents this from happening, but this seems to return false when I start the conversation using DialogueManager.StartConversation(). I suspect this may cause other problems in the future (such as multiple conversations starting at once). Does it make sense to ensure this returns true after starting conversations this way? If so, how can I do so via script?
User avatar
Tony Li
Posts: 21961
Joined: Thu Jul 18, 2013 1:27 pm

Re: Starting conversation/cutscene from script

Post by Tony Li »

If a conversation is active, regardless of whether you use DialogueManager.StartConversation() in C# or use a component, DialogueManager.isConversationActive will be true.

Is it possible that another script is also doing something when you press Esc?
robloxillian
Posts: 27
Joined: Mon Sep 13, 2021 6:55 pm

Re: Starting conversation/cutscene from script

Post by robloxillian »

It turned out pressing escape wasn't the only thing causing the player to be unable to move after a cutscene and something else was keeping the timescale from resetting. I was eventually able to fix the problem by using a separate flag to stop the player moving during cutscenes rather than setting Time.timeScale = 0f.

However, I'm running into a new issue with the typewriter/scrolling audio. It seems that after about 35 characters, the remaining dialogue letters (which normally appear one at a time) all appear at once. Where should I look first to see why this might be happening?

Edit: it seems to skip ahead after "min subtitle seconds" have elapsed. Ideally, I'd like to either always wait until the subtitles are finished before advancing (preferred), or be able to set pause lengths for each line of dialogue. Is there a way to do either of these?
User avatar
Tony Li
Posts: 21961
Joined: Thu Jul 18, 2013 1:27 pm

Re: Starting conversation/cutscene from script

Post by Tony Li »

Hi,
robloxillian wrote: Mon Jan 09, 2023 8:12 pmEdit: it seems to skip ahead after "min subtitle seconds" have elapsed. Ideally, I'd like to either always wait until the subtitles are finished before advancing (preferred), or be able to set pause lengths for each line of dialogue. Is there a way to do either of these?
Yes. To wait until the subtitles are finished and then automatically advance:

1. Set the Dialogue Manager's Display Settings > Subtitle Settings > Continue Button to Never or Optional.

2. Set the Dialogue Manager's Display Settings > Camera & Cutscene Settings > Default Sequence to:

Code: Select all

WaitForMessage(Typed)
robloxillian
Posts: 27
Joined: Mon Sep 13, 2021 6:55 pm

Re: Starting conversation/cutscene from script

Post by robloxillian »

Thank you-- it is now working very close to the way I want. However, there are still some problems:

1. If I set "continue button" to "never", then the conversation never ends.
2. The dialogue window quickly appears and disappears right before the conversation starts.
3. After the first line of dialogue finished typing, it immediately skips to the next with no pause. Previously, I could control this pause using "min subtitle seconds", but this doesn't seem to affect the pause duration after changing "default sequence". Ideally I'd like to have a default pause duration between when a line finishes and when it advances to the next line.

I think some or all of these may be related to the fact that I have nodes in the dialogue tree before and after the nodes that contain dialogue text. Before the first line of dialogue, I have a conversation node with the actor as the NPC and the conversant as the player. The sequence is:

MoveTo(Node1,Npc1,1.5)

The brief dialogue window appearance happens after the NPC finishes moving to the node.

After the last line of dialogue, I have a node with an event in my code (and no sequence or dialogue text). If I put the event on the last dialogue node instead, it solves the problem 1. However, I can imagine situations where I'd want separate nodes at the end, such as branching conditions to select different events, so I'd like a way to ensure it will always advance to the next node after the correct amount of time.
Post Reply