6 Quick Start
Kyle Austad edited this page 2024-11-21 21:34:57 -07:00

Quick Start

Here is the quick start guide for Simple Dialogue. This quick start guide will get you up and running using the included assets on a blank level. You can easily adapt the methods used in the demo character or other included assets to fit your particular project but this guide is a quick start guide to get you going quickly with your dialogue.

Set up the player

If you aren't using the demo BP_ThirdPersonCharacter and have your own player pawn, simply go in and add the AC_DialogueSpeaker component and then define how you want the player to appear in any dialogue they participate in by selecting the newly added component and changing the SpeakerConfig variable to whatever you desire.

Note: Any DialogueColor variable doesn't change the color of the dialogue text itself but rather the name of the speaker.

Set up your dialogue

Next lets define your dialogue. Create a Data Table based on the S_Dialogue struct.

Once you have your data table lets create a simple dialogue to show branches, and events. Add some rows to your data table. The row names can be named whatever you want to easily identify that line of dialogue. In this demo I have setup a simple opening line that then gives the player two choices which each lead to a different ending to the conversation so my row names look like this:

Once your rows have names lets define the dialogue itself. For each row you want to define the text to display, and the dialogue slot. Dialogue slots are used to dynamically assign that line of dialogue to whatever character or actor you want that participates in that conversation or dialogue. Since this demo example will only be one character and the player we just need two slots. The dialogue slots can be any integer, just make sure all the lines you want that character to say have the same value. So for my 'opening' row I will fill out some text and leave the slot as 0.

Next on the 'opening' row, lets define the choices. Under the choices section, enable the 'DisplayChoice?' boolean. This enables choices for that line of dialogue (obviously lol). Next lets add two elements to the Choices array under the boolean. Fill in the text field for what you want the text of the option to show and then under expand each element and assign the data table and row you want the choice to direct to when chosen. For this quick start I point the first option to the choice1 row in the same data table and the second option to choice2 in the same data table. It looks like this now.

Now lets look at each choice row. If you want the player to say something assign the choice1 and choice2 rows a different dialogue slot from the first line. If you don't want the player to say anything and simply have the choice options to represent their speech you can assign the same dialogue slot to these rows. For this example I will have the player say something so I will assign the choice rows a DialogueSlot of 1, different from 0 from before. Fill in the DialogueText and the NextDialogueIfNoChoice variable on each row accordingly. I have choice1 point to ending1 and choice2 point to ending2.

Lastly, just define the text you want each ending to have and leave the NextDialogueIfNoChoice empty. If this field is empty the dialogue will end. For each ending I am also going to add an event from the included demo events called BP_DLGE_ChangeCameraView. This event simply moves the camera to a predifined position from the NPC character. To do this simply enable the TriggerEvent? boolean and add an element to the EventIDs array. Select the event actor from the dropdown so it looks like this:

Now your dialogue is set up! Lets setup our character.

Setting up NPC

In your level, drag out a BP_DialogueCharacter and place them where you want. This demo blueprint includes some pre configured logic for interaction as well as an implementation of starting dialogue. Triggering dialogue is meant to be modular so triggering is performed on the actor component but setting up the layout of which speaker is in which dialogue slot is done on this demo character so that you can define the dialogue layout per character or actor easier.

With your DialogueCharacter in the level, select it and look at the details panel. Under the Dialogue Config category is all the variables you need to define your character and their dialogue. Set the display name and color you want and point the Dialogue to Start variable to the data table we setup previously. The Dialogue Slot variable defines the dialogue slot in the assigned dialogue data table for this character. The Players Dialogue Slot variable does the same for the player. So remember, we setup the NPCs dialogue to be slot 0 and the player in slot 1. If you wanted the NPC to say the players dialogue we could flip these to be 1 and 0, respectively. This is the modular nature of the dialogue system and is very helpful in dialogue with multiple participants. I setup my character like this:

Now jump into game and go interact with your character. The dialogue should work as you have it laid out.

Custom Events

The included events are simple demo events. Events work by spawning a child of BP_DialogueEvent_Base and executing the logic in the OnTrigger event, then calling the parent function to delete the actor. So to create a custom event, create a child class of BP_DialogueEvent_Base, override the event OnTriggerEvent, add your event logic, then if you want the event actor to be destroyed make a call to the parent function at the end of your logic. To add a call to the parent function, right click the event and click on 'Add call to parent function' and add it to the end of your logic. This system is just a regular blueprint editor on an actor so your options are very flexible. The SpeakerIDs variable that is passed into this event from the dialogue that called it contain all the participating dialogue speaker components and their corresponding dialogue slots. So if you want to perform an event on a specific person in the dialogue you can iterate over the keys in this variable and find the matching dialogue slot you want. You can then get the owner of that corresponding component and perform your logic on it. An example of what I described is below.

In this example we find the correct component for the speaker in dialogue slot 1, which should be the player (or whoever you assigned to that slot) and then we can do something on that actor.