Beginner trying to understand Conversations & NPCs talking to Each Other

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 21056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Beginner trying to understand Conversations & NPCs talking to Each Other

Post by Tony Li »

Hi,

> How do I check if any conversations are currently playing before playing barks?

Check DialogueManager.isConversationActive.


> How do I trigger barks the same way that dialogManager.StartConversation(conversationName) works? While barks are tied more to players than the table as a whole, necessitating the Dialog System Triggers, I don't know what the ideal way to set it up is, as there's times where I want characters to respond individually (IE, ending their turn, folding, checking), versus simultaneously (the big dramatic moments).

Use DialogueManager.Bark() to bark a dialogue entry from a conversation, or DialogueManager.BarkString() to bark text that you provide to the method.
2linescrossed
Posts: 31
Joined: Tue May 16, 2023 10:37 pm

Re: Beginner trying to understand Conversations & NPCs talking to Each Other

Post by 2linescrossed »

Hi again, another quick question. I've been making some slow progress, but I've come across a strange issue where the barks are currently invisible, and I'm not sure where to fix it.

Code: Select all

        foreach (Transform player in playerHolder)
        {
            
            convoManager.Bark(barks.dialogConversation, player);
            Debug.Log("Bark is happening");
        }
In this brief code snippet, I'm trying to get the barks playing, feeding in the list of barks (currently just a single conversation with three nodes branching from the start point), and trying to spawn it at the player's position.
Right now, it's a bit of a hack job, as right now I'm just using the transforms instead of a playerprefab where I can grab an Actor component and set it on the bark.
I'm not sure what could be causing the invisible barks, though I'm guessing it potentially has something to do with the conversants/speakers not being set correctly, or not being assigned right in the ScriptableObject I'm using for the conversation? dialogConversation is a string variable that holds the conversation name in it; I've set it directly to the Bark conversation through a dropdown however, so it shouldn't be having any issues there.

In addition, I would like to ask about how you'd go into a different conversation before returning to the core one when a conversation is interrupted - would the best way be creating a set of 'placeholder' conversations full of phrases like "So anyway" or "Like I was saying", calling a trigger to that, waiting for the conversation to conclude, then playing the conversation from where it left off using the advice you've given me prior?

Thanks for the continued support.
User avatar
Tony Li
Posts: 21056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Beginner trying to understand Conversations & NPCs talking to Each Other

Post by Tony Li »

Hi,

There are two ways to jump into another conversation:

1. Link from one conversation to another (e.g., in the Dialogue Editor). In this case, you might link from more than one node to the side conversation. In this case, the side conversation won't know at design time which node to return back to. So instead of adding a link, use the Conversation Position Stack.

2. Or you might want to completely stop the previous conversation, start a new conversation and let it run to the end, and then resume the previous conversation. In this case, you'll need to do a little scripting. Record the previous conversation's conversation ID and entry ID, which are in DialogueManager.currentConversationState.subtitle.dialogueEntry. Then call DialogueManager.StopConversation() to stop it, and to resume use the DialogueManager.StartConversation() method overload that accepts a starting entry ID.


For the barks, does the bark UI's text component contain the bark text? This will tell us if it's using the correct bark UI but the UI isn't visible, or if it's not using the correct bark UI at all. Are there any errors or warnings in the Console?
2linescrossed
Posts: 31
Joined: Tue May 16, 2023 10:37 pm

Re: Beginner trying to understand Conversations & NPCs talking to Each Other

Post by 2linescrossed »

Hello, thanks for the response as usual -
I believe the second method you described is likely the most appropriate one and should work for playing the conversations in the proper order.

That being said, I am still having difficuly solving the Bark issue.
The Bark UI is completely vanilla and unmodified - and I've confirmed through debugging that the code at least goes to the if statements where the Barks are attempted to get played, but nothing appears visually and I do not see any errors in the console when this happens.

I've tried both using a button and the provided 'Bark on Idle' components, but neither are able to create a visible bark.

Incidentally, I am using Unity2D, but with the 'enable 2D support' button enabled, so that shouldn't be a problem.

How important are the 'Barker' and the 'Bark target' fields in the Bark on Idle components?
I can't help but feel like the issue may be stemming from how I am not assigning the Bark's conversation to any particular speaker, (but even when I do assign it to someone specific, nothing happens) but I am unsure what the way forward is.

Code: Select all


        foreach (Transform player in playerHolder)
        {
            
            convoManager.Bark(barks.dialogConversation, player);
            Debug.Log("Bark is happening");
        }
Reposting the code for posterity -
In the Bark Scriptable Object, the only thing in it that SHOULD matter would be the Bark conversation itself, which I believe is correctly linked to the right dialog entry.

That being said, the Bark's dialog nodes have a default player/conversant assignment in the Inspector; am I meant to assign these to the right people for the bark to appear properly? What if I want multiple people to use the same Bark?

(Also, I've tried to upload pngs of the screens here, but the attachment box has been telling me that my files are invalid for some reason.)
User avatar
Tony Li
Posts: 21056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Beginner trying to understand Conversations & NPCs talking to Each Other

Post by Tony Li »

Hi,

Just to double check, are warnings filtered out of the Console window? (You can turn off warnings, etc., using the buttons in the upper right of the Console window.)

In this line:

Code: Select all

convoManager.Bark(barks.dialogConversation, player);
what is convoManager?

For barks, you should specify which character (GameObject) is the barker. The Dialogue System will look for a bark UI in this character's hierarchy. You can add a bark UI yourself, or add a Dialogue Actor component and assign a bark UI prefab to it. The Dialogue Actor will instantiate a copy of the prefab.
2linescrossed
Posts: 31
Joined: Tue May 16, 2023 10:37 pm

Re: Beginner trying to understand Conversations & NPCs talking to Each Other

Post by 2linescrossed »

Hi, I've figured out the root cause of the problem; the sorting layers of the Bark UI.

In my scene, I've got three layers - default, Player and UI.
I want the bark to appear on the UI Layer, as they're being spoken by objects that are on the Player's sorting layer.

The issue is, when I click into the standard bark UI to try and change it to another sorting layer, I'm not given the option, only a 'override sorting' option.
I tried this, but the issue is that this does not actually address the situation: It only changes the sorting order on the same sorting layer, which means it isn't useful for my purposes.

Is there a way i can properly change the sorting layer of the Bark UI?
User avatar
Tony Li
Posts: 21056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Beginner trying to understand Conversations & NPCs talking to Each Other

Post by Tony Li »

Hi,

When you double-click a UI prefab to edit it, Unity may put it inside a temporary Canvas used just for that editing session. Since this temporary Canvas acts as the main Canvas, the bark UI's actual Canvas is treated like a child Canvas, which it won't be when you're actually playing the game.

Instead, inspect the bark UI by single-clicking it. In the Inspector, you should see that you can now change the Sorting Layer.
2linescrossed
Posts: 31
Joined: Tue May 16, 2023 10:37 pm

Re: Beginner trying to understand Conversations & NPCs talking to Each Other

Post by 2linescrossed »

If you want to play different audio clips for each actor, see How To: Vary Character Mumble Speak With Typewriter Effect.

---

To play a single audio clip when the typewriter starts, add a script with an OnConversationLine() method to the actor. Something like:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class PlayAudioOnConversationLine : MonoBehaviour
{
    public AudioClip audioClip;
    
    void OnConversationLine(Subtitle subtitle)
    {
        if (subtitle.speakerInfo.transform == this.transform) AudioSource.PlayClipAtPoint(audioClip, transform.position);
    }
}
---

If you want to play voice acted audio, on the other hand, see the Cutscene Sequence Tutorials.


Hi again - much thanks to your advice, things have generally been going well, though I took a brief hiatus on development.

Right now, I want to ask about the audio implementation of the system again, particularly about the audio system I was implementing.

To be a bit more specific, I want to refocus on how to get the audio effects playing before a subtitle starts playing, to give it the impression of talking without going into mumblespeak.

Currently, I've been studying the script (and the documentation) that you had provided me before, but I'm unsure how to tell the Actor the current subtitle for the OnConversationLine function. I'm also unsure of what the AudioSource in that script is meant to be - I can't use the actor's own audiosource as it tells me that it's a 'Cannot be accessed with an instance reference' kind of member. I'm not sure what that means.

The way I want to go about things - I've divided a large array of different sound effects into tones (good, neutral, bad) and length (short, medium and long). I'm not sure how wise this is as an audio approach, but it's currently my in-between way of handling the character 'speech'.

But to keep it concise:
I'm unsure how to make it so each subtitle/conversation node has its own 'tone variable' - presumably I should employ the Lua stuff in it somehow?
I just want to be able to tell the script whether to use sound effects from a list of 'short and angrysounding' effects, or 'long and happy' for example.
Length could probably be figured out through accessing the subtitle's character count and adjusting appropriately, but I do want to know how to make it so the system/actor can tell whether the subtitle warrants a happy, annoyed or neutral tone of 'voice'.

Is this going to be particularly tedious? I imagine MOST of the conversations in-game are going to be neutral in tone, but I want the extra level of control, being able to make the voices sound happier or angrier for specific topics. I guess I could make the game default to the neutral tones when unspecified though.

I want to also trigger animator triggers for something like this as well with similar conditions, so that the character sprites have the correct expressions for the phrases.

Since a lot of these touch on the subtitle changes and I want to play specific audio & trigger animator/sprite changes on these dialog switches, I want to know how I can give a subtitle triggers to tell the other systems to make the appropriate changes, or have those systems read what the subtitle wants to do when it comes to setting animation triggers or playing specific audio clips.

Thanks in advance!
User avatar
Tony Li
Posts: 21056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Beginner trying to understand Conversations & NPCs talking to Each Other

Post by Tony Li »

Hi,

It's been a while, so I'll ask you to please remind me if I've forgotten some details. Is the summary below correct?
  • You not not want to use mumblespeak tied to the typewriter effect. [TYPO: I meant do not.]
  • For each subtitle, you want to determine the subtitle's mood (good, neutral, bad) and play a single sound associated with that mood.
  • You also want to automatically trigger animation changes on the characters' avatars, not their portrait images in the dialogue UI, based on the subtitle's mood.
If this is the case, I recommend adding a custom field (e.g., "Mood") to the dialogue entry template. (See Templates.) Create a custom field type that's a dropdown with values Neutral, Good, and Bad. In the template, set the Mood field's default value to Neutral. In your OnConversationLine method, check the subtitle's Mood field and set up the audio and animation accordingly.

I'll wait to go into more details until you've confirmed the summary above, since it's quite possible I misunderstood and you actually do want to use the Mood to set up the typewriter's mumblespeak, for example.
2linescrossed
Posts: 31
Joined: Tue May 16, 2023 10:37 pm

Re: Beginner trying to understand Conversations & NPCs talking to Each Other

Post by 2linescrossed »

Tony Li wrote: Sat Sep 02, 2023 8:59 am
  • You not not want to use mumblespeak tied to the typewriter effect.
  • For each subtitle, you want to determine the subtitle's mood (good, neutral, bad) and play a single sound associated with that mood.
  • You also want to automatically trigger animation changes on the characters' avatars, not their portrait images in the dialogue UI, based on the subtitle's mood.
Yep, that is in fact correct, if 'not not' means that I'm not doing mumblespeak!

More that, stylistically speaking - I'm not super fond of how mumblespeak plays on every letter, so I've tried making sound effects that are akin to that - but mimic syllables and common phrases, akin to how Inscryption's small soundbytes simulate talking without being mumblespeak.
Though I would like to add that the sounds associated with the moods are currently a scriptableObject that's actually a list of multiple sound effects of the same mood and length.

The length of the message also matters but I'd likely also manually control that in a similar way.

Mind you, outside of the stylistic choice of making the sound effects 'manually crafted', I'm not sure if what I've outlined is smart or not so you're welcome to correct me if I'm being inefficient about it (ie, the manually setting of specific animation states for the characters with each node of the conversation/subtitle.)

Thanks for asking though and bearing with my inexperience.
Post Reply