Page 1 of 1

Quick Reference Entry Actor

Posted: Tue Jul 21, 2020 9:35 am
by Murble
So I have it so more than two characters talk in each conversation and would like to know how to have them say something as simple as "I am NAME".
I know about the [var=Actor] markup tag, however that seems to only use the conversation actor and not the actor who is currently speaking in the Dialogue entry.

My situation is like this, I have the player and three NPCs talking with each other. Each one will want to introduce themselves by just saying their names. However, I can only seem to store one actor and one conversant to use the markup tag. Of course, I can also create multiple other variables for each of the others names, but I don't want that since it will spam the variable list, and some actors will have similar names since they are assigned one randomly from a list of names(They're generic encounter NPCs as well, such as bandits who are only there to rob you in one scene, so storing their name in a variable is useless).

I have made use of a new variable called TActor, short for This Actor, which changes based on who's currently the actor talking in the dialogue entry. However, to make this work, every dialogue entry I will have to call the UpdateActors() script I made, which to me feels kind of wasteful. And if I accidentally forget to add it for one dialogue entry, which is a huge possibility, it can of course cause inconsistencies.

Is there some simpler way I am missing to insert the name of the actor of the current dialogue entry into the dialogue text? It's fine if not, the way I'm doing now works, but I just wanted to know.

Re: Quick Reference Entry Actor

Posted: Tue Jul 21, 2020 1:18 pm
by Tony Li
Hi,

[var=Actor] will always be the display name of the Conversation Actor assigned to the Dialogue System Trigger's Start Conversation action. If Conversation Actor is unassigned, it will look for a Dialogue Actor component assigned to the conversation's actor, and barring that a GameObject whose name matches the conversation's actor. If it doesn't find any matching GameObject, [var=Actor] will be the name of the actor assigned to the conversation in the editor.

Similarly, [var=Conversant] will always be the display name of the Conversation Conversant, etc.

As you've noted, there are no built-in variables for additional participants.

However, you can write a short OnConversationLine method that, for example, replaces a custom tag "[me]" with the speaker's display name. If you add it to a script on the Dialogue Manager, it will work for all conversations. Example:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class MeTag : MonoBehaviour
{
    void OnConversationLine(Subtitle subtitle)
    {
        subtitle.formattedText.text = subtitle.formattedText.text.Replace("[me]", subtitle.speakerInfo.Name);
    }
}

Re: Quick Reference Entry Actor

Posted: Tue Jul 21, 2020 3:07 pm
by Murble
Wow thanks.
I was going to actually ask how to make a new tag as well when I posted this, but I thought it would be much harder than a couple lines of code which is why I went the whole variable route.
Real helpful.
This especially can help when I want to reference their gender with he/she, him/her, etc.

Re: Quick Reference Entry Actor

Posted: Tue Jul 21, 2020 3:30 pm
by Tony Li
Glad to help! :-)

Re: Quick Reference Entry Actor

Posted: Tue Jul 21, 2020 5:29 pm
by Murble
Actually, now that I mentioned it, I tried the [him], [he] thing to make it change to be appropriate for the gender speaking. And I assigned a new field to the actors called Gender.

However, how can I get the Actor associated with subtitle.speakerInfo to find the Gender field? I noticed I can get the ActorID with subtitle.speakerInfo.id or subtitle.dialogueEntry.ActorID

So mainly, how can I assign to an Actor type with an ActorID? Been looking through the scripting portion of the documentation and only see them getting the id from assigned actors and never getting actors from ids.

Something like:

Code: Select all

Actor speaker = GetActorFromID(subtitle.speakerInfo.id); //Not a real method, but you get what I'm going for.

if(speaker.AssignedField("Gender").value == "Male"){
	//turn [he] to he
	//turn [him] to him
	//turn [his] to his
}
else{
	//turn [he] to she
	//turn [him] to her
	//turn [his] to hers
}

Re: Quick Reference Entry Actor

Posted: Tue Jul 21, 2020 7:16 pm
by Tony Li
Hi,

Use DialogueManager.masterDatabase.GetActor(id):

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class MeTag : MonoBehaviour
{
    void OnConversationLine(Subtitle subtitle)
    {
        subtitle.formattedText.text = subtitle.formattedText.text.Replace("[me]", subtitle.speakerInfo.Name);
        
        Actor actor = DialogueManager.masterDatabase.GetActor(subtitle.speakerInfo.id);
        bool isMale = actor.LookupValue("Gender") == "Male";
        string subjectPronoun = isMale ? "he" : "she";
        subtitle.formattedText.text = subtitle.formattedText.text.Replace("[he]", objectPronoun);
    }
}