Page 1 of 1

Multiple playable characters methods

Posted: Fri Feb 16, 2024 9:15 pm
by Thanatron
I am creating a rogue-lite that has multiple selectable characters. I am trying to incorporate this into the dialogue system. I've read various posts on the forums about various ways this has been handled, but I'm wondering if there is a best method for doing this that is intended or recommended. Each method I've identified has both advantages and drawbacks.

I have different conversations and conversation options for different characters, and I am also playing audio for voices for each different playable character which eliminates some of the simpler options such as just changing the name displayed for the actor within the conversation.

The main two methods that I have identified that work for this context is to have either a generic "Player" actor, or to have specific actors for each character, set the "IsPlayer" variable on character selection, and then manage it after that.

The main advantages to the first option (generic player actor) is that I can have conversations that start out in a generic manner and can then branch off based upon which character is selected via changing variables within the Player actor and then using conditions to check which character is the one being played. The main disadvantages I can see in this situation is that I need to do lots of conditions all over and that managing the audio clips played for different characters will get complex and can be error prone. I would also have to figure out a different method for playing audio clips since my current method isn't conditional, so using the same node to play different audio clips based upon the selected character would be something I would have to tackle for the 'generic' response nodes.

The main advantages for the second option (Changing "IsPlayer" variable at runtime) is that I can then just split off into different conversations depending upon which actor is the player. I wouldn't have to do any condition checks in this method to determine which actor is the player after switching to the specific conversation for that player. Everything would be less cluttered but much more spread out. This is also the main disadvantage because that would essentially eliminate the generic conversation sections from the other option. I would have to have the same node path in different conversations to have the same interaction, and to change these identical parts I would have to go through each conversation to update them.

I would really appreciate advice on which option is the better one, or if there is a third option that is best which I haven't identified yet. I am hesitant to pick one of the two options because I suspect that there are disadvantages that may reveal themselves to either option once I start to build it out to scale, and I am trying to avoid redoing work the best I can.

Thanks for any suggestions or help anyone may give!

Re: Multiple playable characters methods

Posted: Fri Feb 16, 2024 9:39 pm
by Tony Li
Hi,

Create a generic Player actor and specific player character actors -- for example, I'll use Ann, Bob, and Cal here. Tick the Is Player checkbox on all of them.

Write your conversations using the generic Player actor. Set the conversation's Actor dropdown to the Player actor.

Create GameObjects for Ann, Bob, and Cal. Add a Dialogue Actor to each, and set the Actor dropdown to the corresponding actor.

When you start a conversation, you can pass Ann, Bob, or Cal as the player GameObject. To do this, assign Ann, Bob, or Cal to the Dialogue System Trigger's Conversation Actor field, or if you're using C# pass it to DialogueManager.StartConversation(). Any lines that are assigned to Player will instead be spoken by the GameObject you pass to it. More info: Character GameObject Assignments

When the conversation starts, the Dialogue System will set Variable["Actor"] to the name of the actor you passed to the Dialogue System Trigger or DialogueManager.StartConversation(). (More info: Special Variables.) Technically, it will set Variable["Actor"] to the actor's display name, and it will set Variable["ActorIndex"] to a sanitized version of the actor's Name field.

You can check either variable in Conditions:
  • Dialogue Text: "My name is Bob."
  • Conditions: Variable["ActorIndex"] == "Bob"
Variable["ActorIndex"] tends to be more stable, since you're not likely to change the actor's Name, but you might change its display name (e.g., rename Display Name = "Bob the Merciless" to "Bob the Brutal"), or the display name might change if you localize your game to different languages.

You can use Variable["Actor"] in Dialogue Text, too:
  • Dialogue Text: "My name is [var=Actor]."
And you can use Variable["ActorIndex"] in Sequence fields. To play audio, I recommend using entrytags. Typically an entrytag value for a dialogue entry assigned to the Player in conversation ID 7 and entry ID 42 might look like "Player_7_42". So if you save your voiceover audio clip as "Player_7_42", you can use this Sequence:
  • Sequence: AudioWait(entrytag)
and for that dialogue entry it will be equivalent to:
  • Sequence: AudioWait(Player_7_42)
In practice, you'll generally leave dialogue entries' Sequence fields blank and just set the Dialogue Manager GameObject's Display Settings > Camera & Cutscene Settings > Default Sequence: AudioWait(entrytag).

For multiple player characters, you could name your audio files like:
  • Player_7_42_Ann
  • Player_7_42_Bob
  • Player_7_42_Cal
Then set the Default Sequence to:
  • Sequence: AudioWait(entrytag_[var=ActorIndex])
If you've passed Ann as the conversation actor, this will be equivalent to:
  • Sequence: AudioWait(Player_7_42_Ann)

Re: Multiple playable characters methods

Posted: Fri Feb 16, 2024 9:58 pm
by Thanatron
That is incredibly helpful! Thanks Tony! It's very impressive to see how polymorphic the Dialogue System is.

I'm using FMOD for my audio so I'll try to use the FMODWait() sequencer command I've found on the forums in combination with your suggestion for handling dialogue audio.

Your help just made this the best unity asset I've invested in by a significant margin.

Re: Multiple playable characters methods

Posted: Fri Feb 16, 2024 10:16 pm
by Tony Li
Glad to help! You can absolutely use entrytags with FMODWait(). Just incorporate the entrytag into the FMOD event name.