-
Notifications
You must be signed in to change notification settings - Fork 86
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
Actor
with the nameBP_MrCube
. - Open the Blueprint, add a
Cube
component. - Go the the
Class Settings
to add theDlgDialogueParticipant
interface to the implemented interfaces list.
- Open the
GetParticipantName
function - Create a
DialogueParticipantName
variable 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 Name
toMrCube
- Set the
Text
toI am Mr. Cube! What can I do for you?
- Create a new
Speech node
and place it on the right of our first Node.- Set the
Participant Name
toMrCube
- Set the
Text
toGood to See you again!
- Set the
- Save the Dialogue
- Select the first Node you added
- Add an
Enter Condition
- Set the
Condition Type
toWas 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 Node
child fromNode 0
- Set the
Participant Name
toPlayer
- Set the
Text
toCould you change your color?
- Set the
- Add a
End Node
child fromNode 0
- Make and edge from
Node 1
to the newly created Nodes:Node 2
andNode 3
- On the edges leading to
Node 2
set theText
toAsk him to change his color
- On the edges leading to
Node 3
set theText
toLeave
- Add a
Selector Node
child from Node 2- Set the
Participant Name
toMrCube
- Set the
Selector Type
toFirst
- Set the
- Add a
Speech Node
child from theSelector Node
(`Node 4)- Set the
Participant Name
toMrCube
- Set the
Text
toSure. What color would you like to see?
- Set the
- Add a
Speech Node
child from theSelector Node
(`Node 4)- Set the
Participant Name
toMrCube
- Set the
Text
toI 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
MrCube
NPC Blueprint - Add a new
Variable
namedColorChangeRequestCount
- Set the
Type
toInteger
- Compile & Save the Blueprint
- Select the Edge from
Node 4
toNode 5
- Add a new
Condition
- Set the
Condition Type
toCheck Class Int Variable
- Set the
Participant Name
toMrCube
- Set the
Variable Name
toColorChangeRequestCount
- Set the
Operation
to<= (Is Less Than or Equal To)
- Set the
Int Value
to3
- 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 Type
toModify Class Int Variable
- Set the
Participant Name
toMrCube
- Set the
Variable Name
toColorChangeRequestCount
- Set the
Int Value
to 1 - Make sure that the
Delta
checkbox is checked
- Add a new
This will increase the ColorChangeRequestCount
variable each time the dialogue enters this node.
- Add an
End Node
child from theSpeech Node 6
- Add three
End Node
children fromSpeech Node 5
- Set the Edge
Text
in this order from left to right:Red
,Green
,Blue
- Add an
Enter Event
to all three Nodes- The
Participant Name
should beMrCube
- The
Event Type
should beEvent
- The
- Set the
Event Name
in this order from left to right:ColorToRed
,ColorToGreen
,ColorToBlue
- Set the Edge
- Open the
BP_MrCube
Blueprint - Create a new Function with the Name
SetCubeColor
- Add a new Parameter named
Color
of typeVector
- Call
SetVectorParameterValueOnMaterials
on the Cube with theColor
input- Set the
Parameter Name
toColor
- Set the
- Add a new Parameter named
- Create a New Material like in the picture below and set it on the
Cube
Component of theBP_MrCube
Blueprint
- In the
BP_MrCube
Blueprint open theOnDialogueEvent
Function - Place the
Switch on Relevant Dialogue Event
node - it lists the event names associated with Mr. Cube and works as a normal switch node.
- Call
SetCubeColor
depending on Event Name
- Open the Player Blueprint (for example
BP_ThirdPersonCharacter
) - Go the the
Class Settings
to add theDlgDialogueParticipant
interface to the implemented interfaces list. - Add the
DialogueContext
Variable of typeDlgContext
- Add the
DialogueParticipantName
Variable of typeName
and set the Value after compiling the Blueprint toPlayer
- Implement the
GetParticipantName
Function
- Open the
EventGraph
of your Player Blueprint - Add a
Custom Event
with the NameStartDialogueWithNPC
- Set the following inputs
-
Dialogue
of typeDlgDialogue
-
NPC
of typeObject
-
- Start the Dialogue by calling
StartDialogue
- Use the return value of the
StartDialogue
to set theDialogueContext
Variable of the Blueprint
- Open the
EventGraph
of your Player Blueprint - Add a
Custom Event
with the NameSelectDialogueOption
- Set the following inputs
-
OptionIndex
of typeInteger
-
- Call
ChooseOption
(NOTE: we will handle the return value later when we have the UI setup)
- Open MrCube Blueprint and add a
DlgDialogue
variable. 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 Widget
with the nameDlgWidget
and 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
UpdateOption
function. -
Show/Hide and setup everything from tick:
-
Create the widget and add to the viewport in the
BeginPlay
of the PlayerCharacter blueprint. If you worked with blueprint only yourBeginPlay
already 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).