In this video I’ll show you how to set up
some basic branching dialogue in your Godot 4 game. Let’s get into it. I’m starting here with a basic 2D RPG style
project. It just has a very basic character controller
on the player. I can move in four directions and that’s
about it. If you want to follow along then this project
is available on GitHub from the link in the description. Feel free to pause here and go grab a copy. Ok, now that you either have that project
ready or are just imagining it, let’s continue. You can install Dialogue Manager in a couple
of different ways. I’m going to install it from the AssetLib. Click the AssetLib tab and search for “dialogue”. Click it. Click download. Once it’s downloaded you can install it. Now that you have it you can enable it in
plugins. Now we get this dialogue tab at the top here. Sometimes the version on the AssetLib lags
behind so you can see we have an update available. Let’s install that. Now reload the project. Now we’re up to date. From here we can start our first dialogue. Let’s make a folder called “dialogue”. Dialogue is arranged into blocks, starting
with the title line and then dialogue, and then ending with an “end”. Let’s make a really simple one to start
with. We can test this dialogue from here. This opens a special test scene that will
start from the nearest title, which is “start”. Let’s get this into the game. Starting simple again, let’s just make the
dialogue start when we press the space bar. We can add some code to the player input handler
to listen for “ui_accept”. The character script is on Coco here. We have the unhandled input function that
handles her controls. Let’s add it in there. When “ui_accept” is pressed, we can use
the example balloon provided by the dialogue manager to show the dialogue file we just
made starting from “start”. Let’s have a look at that. If I press space bar, it just runs that dialogue. Press space bar again and it ends. That works but it would make more sense to
only show this dialogue if Coco was actually standing in front of Nathan. To do that we can set up what I call “actionables”. Make a new scene based on Area2D. Call it “Actionable” and save it. You can ignore the node configuration warning
because we’ll provide a collision shape later on. The important part is to put this on its own
collision layer. Let’s name some layers. Layer 5 can be “actionables”. There we go. Now let’s define a script with some exports. We need one export to attach the dialogue
file and another to specify which title we are starting from. Lastly, we need a function that will show
the balloon when this actionable gets actioned. Now that we have that we can go back to our
world scene and attach an actionable to Nathan. This is where we can add a collision shape. It doesn’t really matter what the shape
is, as long as it’s big enough to easily hit it. With our actionable selected, we can find
our dialogue file and drag it into the resource slot. Start is start by default which is what we
want so that’s all we need to do there. Ok, so we’re half done with that. Now we need to add something to Coco so that
the game knows when she is close to an actionable. Inside Coco we need another Area2D that can
detect actionables but it also needs to rotate depending on which direction Coco is facing. To do that we add a Marker2D and call it “Direction”. We can put an Area2D as a child of that. It needs a collision shape which sits a little
bit ahead and Direction moves up a little bit so that it’s closer to the center of
where Coco’s base is. This Area2D we’ll call “ActionableFinder”
because that’s what it’s for. And now we make sure that its layer is nothing
and its mask is “actionables”. The layer is the physics layer that its on
and the mask is the one it’s looking for for interaction. Now we need to change each animation so that
the rotation is set. Now that we have that we can modify the player
controller so that when we press “ui_accept” it will see if there is an actionable close
to Coco. First, we need to make a reference to our
actionable finder. Next, we replace our input here with something
that looks for overlapping areas on that actionable finder and it actions the first one. In theory, only actionables will be counted
as overlapping because of the physics layers that we specified. We can turn on “visible collision shapes”
so we can actually see that happening when we run. Let’s have a look. If I press space bar here, nothing happens. If I move up to Nathan and press space bar
now we get dialogue. Now that we have that working, let’s add
some non-linear dialogue. Let’s modify our dialogue file so that Nathan
wants an apple. If you’re wondering where this State apple
status variable comes from the answer is an autoload that I’ll set up now. I’ll make a new script and call it “state”. In here we specify apple status as a string
and nothing by default. Save that and set it up as an autoload called
“State”. Click add. Dialogue Manager uses autoloads to access
game state. Now that we have one we can refer to it by
its name. It is possible to shortcut this process in
settings here. We can set “state” as a shortcut. Once we do that we can get rid of the “State”
at the start of all the references. Now it’s just “apple_status”. Let’s give that a try. There we go. Apple status is empty by default so fails
that check and it fails that check and comes in here. We don’t have any way of updating that apple
status yet so let’s do that now. Back in our world scene, there’s an apple
tree just here. Let’s add an actionable to it. Add a collision shape. Drag our dialogue over again. This time we’ll start from “pick_apple”. We need to define this in our dialogue now. At the bottom, add pick apple. Now that Coco has said that she’s going
to take one we can set apple_status to be “has”. You can see that will match up here and then
we’ll have the option of giving the apple to Nathan. Let’s see what that does. Ok, now we have an apple. We have an option here to give it to Nathan. Which then set it to “gave” so now when
we talk to Nathan, he remembers that we gave him an apple. One more thing that I’ll cover in this video
is doing some simple customising of the dialogue balloon. The font is too small so let’s make it just
a little bit bigger. Dialogue Manager provides a tool script to
clone the example balloon so let’s use that. It asks you where you want to save it so let’s
just put it in the dialogue folder. Now we have this balloon here. Don’t worry too much about how this looks. Everything gets positioned at run time. For now, we’ll resize the character label,
the dialogue label, and the response template to be a bit bigger. 26 might be good. I might also set a minimum size on the margin
container. By default, the dialogue balloon autosizes
based on its content but for this I think I might set it to be a minimum size. In order to use our new balloon, we need to
modify our actionable script. As you can see we’re using the built in
example balloon which points to the one internal to the addons folder. First up, we can import our balloon. Then we replace this bit here with our balloon. Adding it to the tree and starting our dialogue. Let’s see what this looks like. That should be more than enough to get you
started with dialogue in your Godot 4 game. And that’s it for this video. If you did download a copy of this project
and want to jump to the finished version then have a look at the “finished” branch. Until next time, if you have any questions
drop a comment below or jump in my Discord and I’ll see you there or I’ll see you
here again soon. Bye.