Beginner trying to understand Conversations & NPCs talking to Each Other

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

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

Post by Tony Li »

Doh, sorry, that was a typo. I meant to write "You do not want to use mumblespeak."

If you do want to use mumblespeak with the typewriter effect. You can use longer audio clips and UNtick Interrupt Audio Clip. Each character will only play an audio clip if no other audio clip is already playing. If an audio clip is already playing it will let that audio clip finish instead.

If you don't want to use mumblespeak with the typewriter effect, here are two approaches:

1. You could write a custom sequencer command that looks up the current speaker's speech audio and animation and then plays both. For example, you could add two custom fields to your dialogue database's Actor template: Speech and Animation. In your sequencer command, look up the values of the fields. Say the Speech field contains the name of an audio clip. You can put this audio clip in a Resources folder and use Resources.Load() to load it and play it.

2. Or add a script with an OnConversationLine() method that does the same thing, roughly like:

Code: Select all

public void OnConversationLine(Subtitle subtitle)
{
    var actor = DialogueManager.masterDatabase.GetActor(subtitle.speakerInfo.id);
    var audioName = actor.LookupValue("Speech");
    var audioClip = Resources.Load<AudioClip>(audioName);
    var audioSource = subtitle.speakerInfo.transform.GetComponent<AudioSource>();
    audioSource.clip = audioClip;
    audioSource.Play();
}
2linescrossed
Posts: 47
Joined: Tue May 16, 2023 10:37 pm

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

Post by 2linescrossed »

Hi Tony! Thanks again for the assistance!

I've currently been going with option 2 here due to the infrastructure of the NPCs who rely on the subtitle system. Things have been going very well and the implementation of the OnConversationLine function has been exactly what I'm looking for!

I've been reading around this very forum and looking into the ways to make use of the custom fields in the editor, but there was one thing I wanted to ask about in terms of defining and expanding on Custom Fields.

I just want to create something really basic, but I've never had to script a new field for a plugin before. Is it OK if I ask for how to go about creating a basic dropdown menu option for the 'mood' text value so I don't have to type the exact phrases every time?

Currently, I've created a new custom field under Dialog Entries in the templates tab of the Dialog Database - took me a little while to realize I also had to sync the changes across the entirety of the database.
But I want to change those fields from being just a string to a dropdown of a few predetermined moods to prevent myself from mistyping specific moods down the line. (I'm assuming a dropdown would let me select between a few predetermined options that I define in the template).

I've already copied the template file, but I'm unsure what to do next.


I also have a few questions about the custom field types for the DialogDatabase:
- If I update the field type itself by adding more types to it, if I sync it, would that reset ALL the conversations' values, or retain them? (Ie, adding a new mood type when needed, if I don't remove the old moods, then this wouldn't create problems right?)

- A strange new field 'EventGuid' appeared under my Animation and Mood fields in the template, which I don't remember making. Why did it show up and can I remove it without issue?

- With the dropdown, they're still basically strings in terms of how scripts can read/interpret them, right? I'm asking because I'm using a case switch to determine which mood has been identified, and I'm using phrases like "Happy" or "Neutral" to determine what case it is.

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

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

Post by Tony Li »

Hi,
2linescrossed wrote: Mon Sep 04, 2023 11:11 pm...I want to change those fields from being just a string to a dropdown of a few predetermined moods to prevent myself from mistyping specific moods down the line.
See the script Plugins > Pixel Crushers > Dialogue System > Script > Editor > Fields > Examples > CustomFieldType_SceneType.cs. It demonstrates how to turn the field into a dropdown.
2linescrossed wrote: Mon Sep 04, 2023 11:11 pm- If I update the field type itself by adding more types to it, if I sync it, would that reset ALL the conversations' values, or retain them? (Ie, adding a new mood type when needed, if I don't remove the old moods, then this wouldn't create problems right?)
It will keep your settings. It won't reset the conversations' values.
2linescrossed wrote: Mon Sep 04, 2023 11:11 pm- A strange new field 'EventGuid' appeared under my Animation and Mood fields in the template, which I don't remember making. Why did it show up and can I remove it without issue?
When you add an OnExecute() UnityEvent > Scene Event to a dialogue entry, it creates an EventGuid field that connects the dialogue entry to a DialogueSystemSceneEvents component in a scene. (Adding the OnExecute() > Scene Event also automatically creates the DialogueSystemSceneEvents component in the scene if necessary.)

If you're in the Dialogue Editor's Templates section and select Menu > Update Template From Assets or Sync Assets and Template, the Dialogue Editor will detect that some dialogue entry in your database has an EventGuid field and add will add the field to the template.

If you're sure that you're not using any scene events, you can remove the field from the template. Otherwise you can leave it there. If the field's value is blank, it won't do anything except take up a tiny amount of space in your database.
2linescrossed
Posts: 47
Joined: Tue May 16, 2023 10:37 pm

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

Post by 2linescrossed »

Hey again, progress is still going pretty well!

I have encountered a few problems however -

- For some reason, my script can't recognise any objects in the scene with the right DialogueActors for the OnConversationLine function.

It can still return the right ID and name of the speaker, but even when there's gameobjects/prefabs of the right setting, it doesn't recognise them.
My current theory is that this is because I'm instantiating the objects so it may miss the 'timing' for when the DialogManager looks for the objects in the scene with the right DialogueActors, but I'd appreciate suggestions on what I can do to fix this issue. This is also partially a problem because I think this is also causing another problem where I can't filter my list of conversation scriptable objects because the system doesn't find the right things in the scene.

I've also been wanting a bit more fine control over the way the subtitles are displayed -
Sometimes the minimum time length for the subtitle is a bit unpleasantly long, is a good way of resolving this checking the length of the subtitle and adjusting the minimum time a subtitle can be shown for?

I'd also like to know how to change text speed since I couldn't find it in the settings.

Much thanks for the continued advice and suggestions.
User avatar
Tony Li
Posts: 22114
Joined: Thu Jul 18, 2013 1:27 pm

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

Post by Tony Li »

Hi,
2linescrossed wrote: Sun Sep 10, 2023 10:45 am- For some reason, my script can't recognise any objects in the scene with the right DialogueActors for the OnConversationLine function.

It can still return the right ID and name of the speaker, but even when there's gameobjects/prefabs of the right setting, it doesn't recognise them.
My current theory is that this is because I'm instantiating the objects so it may miss the 'timing' for when the DialogManager looks for the objects in the scene with the right DialogueActors, but I'd appreciate suggestions on what I can do to fix this issue. This is also partially a problem because I think this is also causing another problem where I can't filter my list of conversation scriptable objects because the system doesn't find the right things in the scene.
The DialogueActor component registers itself with the Dialogue System in OnEnable(), overriding any Dialogue Actor that may have previously registered under the same actor name. It unregisters itself in OnDisable().
2linescrossed wrote: Sun Sep 10, 2023 10:45 amI've also been wanting a bit more fine control over the way the subtitles are displayed -
Sometimes the minimum time length for the subtitle is a bit unpleasantly long, is a good way of resolving this checking the length of the subtitle and adjusting the minimum time a subtitle can be shown for?
Each subtitle stays onscreen for the duration of its sequence.

Exception: If you've enabled continue buttons (Dialogue Manager GameObject > Display Settings > Subtitle Settings > Continue Button dropdown), the player may skip ahead before the sequence has finished, or the subtitle may stay onscreen even after the sequence has finished, waiting for the player to click the continue button.

The Dialogue Manager's Display Settings > Camera & Cutscene Settings > Default Sequence is set to:

Code: Select all

Delay({{end}})
This delays for a number of seconds specified by the keyword {{end}}. This value is determined by the text length and the values of Subtitle Settings > Subtitle Chars Per Second and Min Subtitle Seconds. If you want to advance sooner, increase Subtitle Chars Per Second and/or decrease Min Subtitle Seconds.
2linescrossed wrote: Sun Sep 10, 2023 10:45 amI'd also like to know how to change text speed since I couldn't find it in the settings.
If you're talking about the typewriter speed, inspect the typewriter effect on the Subtitle Text GameObject. Adjust Characters Per Second. Note: The typewriter's Characters Per Second is not connected to the sequence (e..g, the {{end}} keyword). In you're using {{end}}, make sure Characters Per Second is not less than the Dialogue Manager's Subtitle Settings > Subtitle Chars Per Seconds or the typewriter won't finish before the conversation advances.

If you want to advance as soon as the typewriter finishes, set the Dialogue Manager's Camera & Cutscene Settings > Default Sequence to:

Code: Select all

WaitForMessage(Typed)
The typewriter effect sends the sequencer message "Typed" when it's done. Note: If you're using Text Animator, see Text Animator Integration.

Although not rarely used, you can also change the typewriter speed mid-subtitle. There are threads here in the forum on that.
2linescrossed
Posts: 47
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: Sun Sep 10, 2023 11:42 am
The DialogueActor component registers itself with the Dialogue System in OnEnable(), overriding any Dialogue Actor that may have previously registered under the same actor name. It unregisters itself in OnDisable().
Ahh, okay, that would explain it - though I'm not quite sure how to resolve it.

To explain the current way I'm initializing the objects through creating prefabs, then having those prefabs initialize their player values using a list of ScriptableObjects containing those values.

In my initial tests, the DialogueActors were already present in the scene, so their DialogueActors were present immediately.

Here though, I'm unsure how to get it sorted -
The dialogue actor on the prefab is simply set to a null actor, before having it changed via the scriptable object when it initializes the values. Is there something I can do, like flicking the component on and off again (via OnEnable and OnDisable) to re-register it with the Dialogue Manager/the system?
User avatar
Tony Li
Posts: 22114
Joined: Thu Jul 18, 2013 1:27 pm

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

Post by Tony Li »

Hi,

Yes, you can disable and re-enable the Dialogue Actor:

Code: Select all

var dialogueActor = GetComponent<DialogueActor>();
dialogueActor.enabled = false;
dialogueActor.actor = "My New Actor";
dialogueActor.enabled = true;
Or you can unregister and re-register the actor, which will probably be easier to understand if you go back to this code a year later:

Code: Select all

var dialogueActor = GetComponent<DialogueActor>();
CharacterInfo.UnregisterActorTransform(dialogueActor.actor, this.transform);
dialogueActor.actor = "My New Actor";
CharacterInfo.RegisterActorTransform(dialogueActor.actor, this.transform);
Post Reply