-
Notifications
You must be signed in to change notification settings - Fork 103
Example Tutorial Blueprint
[[TOC]]
ℹ️ NOTE: The FINAL Example Project is here
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 on the Blueprint and Set the value toMrCube.

- 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
TopDownControllerBlueprint and add aDlgContextvariable. Make it public.
-
Add the
StartDialoguefunction. Input parameters are aDialogueand anObject. Use the return value to set the ActiveContext variable.
-
Add the
SelectDialogueOptionfunction.
- Open MrCube Blueprint and add a
DlgDialoguevariable. Set the default value toDlgMrCube. - Add a
SphereCollision Component, and a Component Begin Overlap event. - Setup the event based on the image
If you used blueprint only your PlayerCharacter and PlayerController have a different name then the ones used in the images of this section. Other than that everything should work fine - just use your own blueprints for those.
-
Create a new
User Widgetwith the nameDlgWidgetand construct the setup based on the image. All the variable is anchored to the bottom left and all the texts are marked to be variables.
-
Add the button pressed events.

-
Create the
UpdateOptionfunction.
-
Show/Hide and setup everything from tick:

-
Create the widget and add to the viewport in the
BeginPlayof the PlayerCharacter blueprint. If you worked with blueprint only yourBeginPlayalready contain some code. Adding the nodes from the image to the beginning of your Event BeginPlay works fine.
Set the return value of the GetDlgParticipantIcon functions in both the character and the MrCube blueprint.
Place MrCube to 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).