-
Couldn't load subscription status.
- Fork 96
Example Tutorial Blueprint
- ℹ️ NOTE: 🏢 The FINAL Example Project is here
- ℹ️ NOTE: 🎥 There is a video tutorial version here in this playlist
- 1. Introduction
- 2. Getting started
-
3. Setting up an NPC and a Dialogue
- a. Create a new NPC
Blueprint -
b. Implement the
GetParticipantNameFunctions - c. Create & Open
Dialogue - d. Setup
Participant NameandTexton first Node - e. Setup first Node enter condition and create second Node
- f. Setup Player Node and first End Node
- g. Add Selector Node and the two Speech Nodes
- h. Add
ColorChangeRequestCountVariable to the NPC Blueprint - i. Setup
ColorChangeRequestCountEdge Condition - j. Setup
ColorChangeRequestCountNode Enter Event - k. Setup Final End Nodes
- l. Make Cube NPC Blueprint change his Color
- a. Create a new NPC
- 4. Setting up the Player
- 5. Starting the Dialogue
-
6. UI
- a. Create the
UI_DialogueOptionButton Widget -
b. Setup the
UI_DialogueOptionButton Widget - c. Create the
UI_DialogueWidget -
d. Setup the
UI_DialogueWidget - e. Create the
UI_DialogueWidget on Begin Play - f. Setup UI in
StartDialogueWithNPCof the Player Blueprint - g. Setup UI in
SelectDialogueOptionof the Player Blueprint
- a. Create the
- 7. Start
- 8. Other
ℹ️ NOTE: 🏢 The FINAL Example Project is here
ℹ️ NOTE: 🎥 There is a video tutorial version here in this playlist
The purpose of this tutorial is to teach you how to use the dialogue system and how to integrate it into your own project.
The tutorial starts from the Third Person template project.
At the end the player character will be able to talk to our NPC, Mr. Cube and ask him to change his color. Mr. Cube will be happy to do that at the first few times, then he gets annoyed and won't change his color anymore.
- Create new project using the Third Person Blueprint template project with the name DlgExample.
- Install plugin from marketplace / Get the plugin source from our repository (Click HERE)
- Create a new Blueprint based on
Actorwith the nameBP_MrCube. - Open the Blueprint, add a
Cubecomponent. - Go the the
Class Settingsto add theDlgDialogueParticipantinterface to the implemented interfaces list.

- Open the
GetParticipantNameFunction - Create a
DialogueParticipantNameVariable ofTypeequal toNameon the Blueprint and set the value toMrCube.

NOTE: Only Used in the UI
- Open the
GetParticipantDisplayNameFunction - Create a
DialogueParticipantDisplayNameVariable ofTypeequal toTexton the Blueprint and set the value toMr. Cube.

- Switch to the Content Browser
- Create a Dialogue asset with the name
Dlg_MrCube - Open the Dialogue
- Drag an edge from the border of the start node and place a
Speech node.

- With the recently added node selected, set the
Participant NametoMrCube - Set the
TexttoI am Mr. Cube! What can I do for you?

- Create a new
Speech nodeand place it on the right of our first Node.- Set the
Participant NametoMrCube - Set the
TexttoGood to See you again!
- Set the
- Save the Dialogue
- Select the first Node you added
- Add an
Enter Condition - Set the
Condition TypetoWas node already visited? - The node index has to match the white number on the top right corner of the selected node
- Make sure that the
Is Node Visited?checkbox is unchecked
- Add an
This setup will make sure that MrCube will say his name only the first time the player talks to him.
Observe the fact that the node has an icon on its top left corner - that means that it has an Enter Condition.

- Add a
Speech Nodechild fromNode 0- Set the
Participant NametoPlayer - Set the
TexttoCould you change your color?
- Set the
- Add a
End Nodechild fromNode 0 - Make and edge from
Node 1to the newly created Nodes:Node 2andNode 3 - On the edges leading to
Node 2set theTexttoAsk him to change his color - On the edges leading to
Node 3set theTexttoLeave

- Add a
Selector Nodechild from Node 2- Set the
Participant NametoMrCube - Set the
Selector TypetoFirst
- Set the
- Add a
Speech Nodechild from theSelector Node(Node 4)- Set the
Participant NametoMrCube - Set the
TexttoSure. What color would you like to see?
- Set the
- Add a
Speech Nodechild from theSelector Node(Node 4)- Set the
Participant NametoMrCube - Set the
TexttoI can't keep changing my color all the time! Just leave me alone!
- Set the
This selector node automatically select the first child with satisfied conditions.

- Open the
MrCubeNPC Blueprint - Add a new
VariablenamedColorChangeRequestCount - Set the
TypetoInteger - Compile & Save the Blueprint

- Select the Edge from
Node 4toNode 5- Add a new
Condition - Set the
Condition TypetoCheck Class Int Variable - Set the
Participant NametoMrCube - Set the
Variable NametoColorChangeRequestCount - Set the
Operationto<= (Is Less Than or Equal To) - Set the
Int Valueto3
- Add a new
This will check the ColorChangeRequestCount variable (you will have to type it the first time you use it).
If it is less than or equal to 3 then Mr. Cube will be happy to change his color.
This selector node automatically select the first child with satisfied conditions - so each time the player asks Mr. Cube to change its color it will either say the text of Node 5 or Node 6 depending on the variable value.
This ColorChangeRequestCount variable will be Modified by the Dialogue in the next step.

- Select the
Speech Node 5- Add a new
Enter Event - Set the
Event TypetoModify Class Int Variable - Set the
Participant NametoMrCube - Set the
Variable NametoColorChangeRequestCount - Set the
Int Valueto 1 - Make sure that the
Deltacheckbox is checked
- Add a new
This will increase the ColorChangeRequestCount variable each time the dialogue enters this node.

- Add an
End Nodechild from theSpeech Node 6 - Add three
End Nodechildren fromSpeech Node 5- Set the Edge
Textin this order from left to right:Red,Green,Blue - Add an
Enter Eventto all three Nodes- The
Participant Nameshould beMrCube - The
Event Typeshould beEvent
- The
- Set the
Event Namein this order from left to right:ColorToRed,ColorToGreen,ColorToBlue
- Set the Edge

- Open the
BP_MrCubeBlueprint
- Create a new Function with the Name
SetCubeColor- Add a new Parameter named
Colorof typeVector - Call
SetVectorParameterValueOnMaterialson the Cube with theColorinput- Set the
Parameter NametoColor
- Set the
- Add a new Parameter named

- Create a New Material like in the picture below and set it on the
CubeComponent of theBP_MrCubeBlueprint

- In the
BP_MrCubeBlueprint open theOnDialogueEventFunction - Place the
Switch on Relevant Dialogue Eventnode - it lists the event names associated with Mr. Cube and works as a normal switch node.

- Call
SetCubeColordepending on Event Name

- Open the Player Blueprint (for example
BP_ThirdPersonCharacter) - Go the the
Class Settingsto add theDlgDialogueParticipantinterface to the implemented interfaces list. - Add the
DialogueContextVariable ofTypeequal toDlgContext
- Open the
GetParticipantNameFunction - Add the
DialogueParticipantNameVariable of typeNameand set the value toPlayer

NOTE: Only Used in the UI
- Open the
GetParticipantDisplayNameFunction - Add the
DialogueParticipantDisplayNameVariable of typeTextand set the value toPlayer(or whatever you want)

- Open the
EventGraphof your Player Blueprint - Add a
Custom Eventwith the NameStartDialogueWithNPC - Set the following inputs
-
Dialogueof typeDlgDialogue -
NPCof typeObject
-
- Start the Dialogue by calling
StartDialogue - Use the return value of the
StartDialogueto set theDialogueContextVariable of the Blueprint


- Open the
EventGraphof your Player Blueprint - Add a
Custom Eventwith the NameSelectDialogueOption - Set the following inputs
-
OptionIndexof typeInteger
-
- Call
ChooseOption(NOTE: we will handle the return value later when we have the UI setup)

- Open the
BP_MrCubeBlueprint - Add a
Sphere CollisionComponent as a child of theCubeComponent- Set the
Sphere Radiusto300.0
- Set the

- Open the
EventGraphon theBP_MrCubeBlueprint - Add a Variable with the Name
Dialogueof TypeDlgDialogue- Set the value to
Dlg_MrCube
- Set the value to
- Add a
On Component Being Overlapon theSphere CollisionComponent you added in step a. - Cast the
Other Actorto your Player Blueprint and callStartDialogueWithNPC(created here)

The UI will be composed from two widgets
-
UI_DialogueOption- Which is just a button with a text, this represents a dialogue option -
UI_Dialogue- Which is the main UI widget that containsText,Participant Nameand the multiple ``UI_DialogueOption` options
ℹ️ Example widgets UI_DialogueOption and UI_Dialogue you can copy/look at are in the Example Project
- Switch to the Content Browser
- Create a new Widget Blueprint with the name
UI_DialogueOption - Open the
UI_DialogueOptionWidget Blueperint - Add a
Button Widgetwith the nameButtonX- Set it as the root of the widget
- Add a
TextBlock Widgetas a child of the Button, with the nameOptionText - Make them both as
Variables

- Switch to the
Graphof theUI_DialogueOptionWidget Blueperint - Add a new Variable of
Typeequal toIntegerandNameequal toOptionIndex - Compile & Save the Blueprint
- Select the
ButtonXButton and add the following three events:On Clicked,On Hovered,On Unhovered - From the
On ClickedcallSelectDialogueOption(created here) on your Player Blueprint - From the
On Hoveredevents set the color of yourOptionText

- Add a Custom Event with the Name
Update

- Add as input a Parameter with the
Nameequal toContextandTypeequal toDlgContext - Update the
OptionTextonly if theOptionIndexis Valid and set the widget visibility in each case

- Switch to the Content Browser
- Create a new Widget Blueprint with the name
UI_Dialogue - Open the
UI_DialogueWidget Blueperint - Set a
Canvas Panel Widgetas the root - Add the following
TextBlock Widgets:SpeakerNameandText - Add a
VerticalBox Widgetwith the Name equal toOptions- Add four
UI_DialogueOption Widgetsinside this vertical box - Set the
Option Indexfor each of them
- Add four
- All these Widgets should be
Variables - All the
Variablesare anchored to the bottom left

- Switch to the
Graphof theUI_DialogueWidget Blueperint
- On
Event Constructhide this Widget - Add a Custom Event with the Name
Close- Which hides this Widget
- And sets the Input Mode and Hides the Mouse

- Add a Custom Event with the Name
Update - Set the
SpeakerName,TextandAvatar(Optional) - Iterate over all the
UI_DialogueOption Widgetsand callUpdate(created here) on them

- Add a Custom Event with the Name
Open - Set this Widget to
Visible - Set the Input Mode and Show the Mouse
- Call the
Updateevent on this Widget you created previously

- Open the Player Blueprint (for example
BP_ThirdPersonCharacter) - Create a
UI_DialogueVariable ofTypeequal toUI_Dialogue(This is the Dialogue Widget you created above) - Open the
EventGraphand onEvent BeginPlayCreate the new widget and add it to viewport

- Go to the
StartDialogueWithNPCEvent you Created - There at the end
OpentheUI_Dialogue

- Go to the
SelectDialogueOptionEvent you Created - There at the end
UpdatetheUI_Dialogue - And reset the
DialogueContextandClosetheUI_DialogueifChooseOptionreturnsfalse

- Place the
BP_MrCubeBlueprint in the level - If you start the game and go near him the dialogue should start
- You can ask him to change his color four times before he gets annoyed
- Leaving him and returning again triggers the dialogue again

- Open your
GameModeBlueprint (for exampleBP_ThirdPersonGameMode) - On
Event Begin PlaycallRegister Dialogue Console Commandsand `Clear Dialogue History - On
Event End PlaycallUnregister Dialogue Console Commands
