Dialog System

Name: Dialog System
By AdamO in Discord

(Very basic) Example game - Crayta


The Dialog System allows you to add dialog trees to your game with easily customisable UI.

The Dialog System is an ideal solution for:

  • Talking to NPCs
  • Quest-givers
  • Game story / introduction
  • Puzzle games that require NPC interaction
  • Conditional dialog (based on if you’ve interacted before, or any other conditions)

QUICK set up guide

  • Drop the DialogNPC_Example template into your game
  • Add the UserDialog template (script folder) to your User template
  • Preview the game and interact with the NPC to talk to it
  • In the editor, look at how the dialog is set up on locators under the NPC, and try adjusting it yourself!

Customisation


The dialog UI can be customised on the UserDialog template, where there’s many options for the colours, layout, sizes and more of the dialog UI.


FULL set up guide
The dialog can be attached to an NPC, or it can exist in the world by itself. Either way, a DialogControl entity is required (there’s a template for this, or it comes with the DialogNPC template).

Any dialog system is based on a DialogControl entity

DialogControl
A DialogControl comes with the dialogControlScript. This is where the dialog is started from, so you need to set the startMessage to your first dialog message. The DialogControl includes:

  • Start message - this will be the first message displayed to the User. It could also be a decision - see the section on DialogDecision below.
  • Camera - the User will be set to this camera during the dialog, except for messages which have their own camera set.
  • NPC - optionally, an NPC can be set here, for dialog emotes to be played on. You can have dialog, like a tutorial, without an NPC attached.
  • Speaker image URL - an optional URL of an image that is displayed in the dialog UI, showing the speaker.
  • Speaker name - an optional name of the speaker, displayed in the dialog UI.
  • Start dialog prompt - the prompt that will be shown to start the dialog (requires the Prompts package).

A dialog tree is made up of messages and responses.

DialogMessage
A message is what the dialog speaker says (e.g., the NPC). It should be made up of a locator entity with a DialogMessage script. A DialogMessage includes:

  • Message text options - one of these texts will be displayed when the User reaches this message. You can have as many texts as you want, for more random variation.
  • Message sound - this sound is played to the User when the message is displayed.
  • Message camera - if you want to override the camera when showing a particular message, e.g. to highlight a gameplay area in a tutorial, you can set this property to a camera entity.
  • Message emote - if the DialogControl has a DialogNPC assigned, it will play this emote when the User reaches this message. NOTE - it can only play emotes if there’s just 1 user currently talking to the NPC, because emotes are played on the server and they’d interfere if 2 users are talking to it.
  • Message image - this will display in the dialog UI, replacing the speaker image.
  • Message event - this event can be used to trigger in-game actions when the user reaches this message. The event is called on the local client as standard, but you can tick “DoEventOnServer” if it needs to be run on the server. Be aware that an event played on the server will be called for ALL users in the game.
    • If you want to call an event on the user that’s speaking to this NPC, see the section on DialogUserAction below.

DialogResponse
A response is what the User can say back in response to the message. Every DialogMessage entity should have at least one DialogResponse script attached, so that the User can respond to the dialog. A DialogResponse includes:

  • Response text - this is text that the user will select as their response. For linear dialog (e.g. a tutorial, or game narration) this might just be “Next” or “Okay”.
  • Next message - this should contain the next message entity that will be displayed if the User selects this response. Or, it could be the next decision entity (see the section on DialogDecision below). NOTE - if this is left blank, it will end the dialog. You MUST leave at least one response without a “Next Message” so that the user can reach the end of the dialog.

The logic of the dialog can be controlled by decisions.

DialogDecision
A dialog decision can take the place of a dialog message. It can check a query in the world, and then either go to a “positive message” or “negative message” based on whether the query criteria are met. A decision includes:

  • Query function - this should be the name of a function that exists in a script on the User. Because this is being openly sent to scripts on the User, the query function needs to take a “responseData” table parameter, and set responseData.result to the desired result - true or false, in the case of a boolean result being expected.
  • Argument type - you can send an argument with the query. E.g. in the example, it queries “HasInteracted” with the string “robot”, to check if the user has specifically interacted with the Robot character before. The type can be none, string, number or boolean.
  • String / Number / Boolean arg - the argument to pass with the query.
  • Response type - the query should return a result in the given type - string, number or boolean.
  • String / number / boolean response - the expected response.
  • Positive message - if the query criteria are met, i.e. the given response is “true” and the expected response is “true”, then the positive message will be the next message displayed to the User.
  • Negative message - if the query criteria are not met, then the negative response message will be the next message displayed.

DialogUserAction
A dialog user action allows you to trigger an action on the User, from a dialog message’s event. In the DialogNPC_Example, a dialog user action is used on the “Msg_Goodbye” which tells the user that it has interacted with this robot. A user action includes:

  • Function name - the name of the function that will be called on the User
  • Argument type - you can pass an argument with this function, with string, number or boolean type.
  • String / number / boolean arg - the argument passed with the function.

UserSaveInteraction
The UserDialog script folder contains a “user save interaction script”. This works with the “Msg_Goodbye” and the “Decision_HasInteracted” in the DialogNPC_Example to save whether you’ve spoken to this NPC before. This is a handy script that can store which NPCs you’ve spoken to, for a story-driven game where you want to have many characters that “remember” your interactions. You can also look at how the logic is set up, to make similar logic for, e.g., check if the user has a certain item in their inventory before showing them a particular message.

11 Likes

Love it! This is a great package to have.

1 Like

Why you didn’t called “Simple” Dialog System? Now I won’t find it! XD Jk, this is great, love it <3

2 Likes

Amazing !

1 Like

Great package :slight_smile:

1 Like

Hi Adam! I’ve been playing with this and find a small issue. When I interacted with a second NPC the dialog from the first NPC in my map opened. It was because the event on the interact trigger wasn’t set to call the dialogControlScript on the specific NPC. Once I dragged the DialogControl into the OnInteract event it worked perfectly.

Oops! Thanks for pointing out. Fixed and updated the package

@tumbak7 because I spent like a whole day writing this package guide, it doesn’t feel very “simple” :wink:

1 Like

@Adam Hey adam, could we get an event that fires when a response is selected?

Right now, you can kind of do this by setting up another message that has a messageEvent, but that message still requires text, and you need to manually dismiss it immediately in the event. It would be a lot more convenient to have a response just delegate control off to something else and exit the dialog completely

2 Likes

Hey, Adam, I came here to request events on responses and found Cereal already asked, so here’s my upvote. :slight_smile:

@Cereal @Mad-Eye added a response event to the dialog responses, works the same as the message event. Sorry I took so long getting around to it :wink:

1 Like

Thank you for adding it! It would have been really helpful during the Jam