Announcement

Collapse
No announcement yet.

[Tutorial] Very basic dialogue system

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Tutorial] Very basic dialogue system

    Hey All,

    I've seen some pretty interesting ideas for dialogue systems, including one by Adam @ Epic (https://wiki.unrealengine.com/NPC_Di...ystem_Tutorial) and thought I would show my own idea on how to create one. This system is very bare bone, but could be modified very easily once you understand it. I think it works pretty good but would love feedback as I plan to modify it in the future.

    Anyhow, this project is very simple to set up. please let me know if I have mistakes that need to be fixed.

    Edit: Project type is third person and version is 4.7

    This tutorial will need the following things made in the content browser:
    2 widgets:
    • Choices
    • DialogueScreen

    3 structs:
    • DialogueTree
    • NPC_Reply
    • PC_Choices

    1 actor:
    • DialogueSystem


    The first thing we need to do is in the MyCharacter BP. Add the following two functions and run them on the event begin plays as follows:

    Event Graph:
    Click image for larger version

Name:	Character Event Graph.PNG
Views:	1
Size:	42.4 KB
ID:	1146339
    Init Mouse: Make sure to set all the bools to true
    Click image for larger version

Name:	Init Mouse.PNG
Views:	1
Size:	85.1 KB
ID:	1142568
    Spawn Dialogue: You do not need to promote the transform to a variable like I did, I just prefer it over the make transform.
    Click image for larger version

Name:	Spawn Dialogue.PNG
Views:	1
Size:	71.7 KB
ID:	1142569


    The second thing to do is to set up how the widgets will look in the designer.

    Choices Widget
    This widget is simple, just add a text box and wrap it with a button.
    The text needs to be a variable, mine is ChoiceText.
    The button does not need to be but make sure "Size to Content" is set to true. Also add an "On clicked" event to this button. The only code for this widget goes there.

    Inside the widget add two variables
    Bool - Exit Conversation
    Integer - Link To Node

    Here is the how the BP looks but you won't be able to set it up until we make the Load Dialogue Function in our Dialogue Actor.
    Click image for larger version

Name:	Choices Widget.PNG
Views:	1
Size:	120.8 KB
ID:	1142570

    Dialogue Screen Widget
    This widget has no code so you can set it up however you'd like but this is how I set it up:
    Click image for larger version

Name:	DialogueScreenWidget.PNG
Views:	1
Size:	11.7 KB
ID:	1142571

    NPC Responses text must be a variable
    Choices border does not need to be a variable like it shows in mine but I would set it's size to fill.
    Choices Vert Box needs to be a variable

    Now lets set up our structs, they are pretty straight forward.

    PC_Choices
    Text - Reply
    Integer - LinkToNode
    Bool - ExitDialogue

    NPC_Reply
    Text - NPCReply
    PC_Choices(struct) - PC_Choices (make it an array)

    DialogueTree
    NPC_Reply(struct) - Conversation (make it an array)

    Click image for larger version

Name:	StructSetup.PNG
Views:	1
Size:	115.5 KB
ID:	1142572

    Dialogue Actor
    Don't forget that once you set this up, you can go back to the choices widget and set it up correctly.

    Create one custom variable and set it to the type "Dialogue Tree (struct)" - I named mine dialogue test for this.

    Event Graph
    Click image for larger version

Name:	Event Graph.PNG
Views:	1
Size:	95.0 KB
ID:	1142574
    Promote the return value from the create widget and set it to Dialogue Widget

    Create a new function "Start Conversation"
    Click image for larger version

Name:	Start Conversation.PNG
Views:	1
Size:	75.4 KB
ID:	1142575
    Promote the as dialogue screen value and set it to Dialogue Screen Cast

    Create a new function "Load Dialog"
    This is a bigger function so it will be multiple screen shots.

    Part 1
    Click image for larger version

Name:	Load1.PNG
Views:	1
Size:	154.5 KB
ID:	1142576

    Part 2
    Click image for larger version

Name:	Load2.PNG
Views:	1
Size:	264.1 KB
ID:	1142577

    Now for the last part, setting up the actual conversations and how it works.

    This may be kind of confusing at first so I will do my best to explain it since this is the guts of the setup.

    In the dialogue actor, click on the variable you made called dialogue test. (for my screen shots, I drug the details panel out into the open and set it to full screen to set this up, makes it easier)

    Here is the opening statement and what it would look like when fully expanded.

    Click image for larger version

Name:	Opening.PNG
Views:	1
Size:	34.6 KB
ID:	1142579

    NPC_Reply: This is the text that will fill the screen above the players choices, its pretty straight forward. Each time you add another element it becomes a new "screen" that is accessible for the player. (the elements array number is the number you'd use in the link to node below)

    Conversation: This is an array/list of choices you can set for the player to pick from. Each element you add will become an option the player can click on

    Link to Node: This is used to pick which screen you want to load next.

    Exit Dialogue: If this is set to true, and the player clicks it, the dialogue menu will close.

    In the picture above, you can see this conversation is Node 0 - This means it will be the opening conversation. You can also use 0 to link back to this screen from any other PC_Choice you'd like to.

    here is another picture:
    Click image for larger version

Name:	Options.PNG
Views:	1
Size:	69.5 KB
ID:	1142580

    In this picture you can see I added another conversation screen. If the player chooses the option for "wanting more information" I set the link to node to 1 which will load the next screen.

    The other two I left at 0 for now so it will just reload the same screen but the you'll notice the third has the exit convo set which will end the conversation (by hiding the widget)

    In the second conversation, every option will link back to the first screen creating an infinite loop of sorts.

    Edit: Another way you can do this too is when you set the dialogue widget, change the variable type from User Widget and set it to the Dialogue Screen and you can remove the start conversation function altogether and replace all the existing dialogue cast nodes with the dialogue widget variable.
    Click image for larger version

Name:	Edit.PNG
Views:	1
Size:	99.7 KB
ID:	1142603

    Edit: Here is what it looks like in game
    Click image for larger version

Name:	Ingame.PNG
Views:	1
Size:	801.8 KB
ID:	1142581


    You can expand on this system infinitely.

    If you have any questions or feed back on how this system could be made easier/ more efficient please let me know.



    In the future I do plan to add more features like activating quests, opening shop menus, and many other things. I just hope this helps some people with basic dialogue systems.
    Last edited by Hakabane; 03-18-2015, 02:52 AM.
    Movable Widgets

    #2
    Hello,
    Another cool gift ! Thank you ^^

    Edit : Have you seen this one too ? https://forums.unrealengine.com/show...on-BP-Tutorial i haven't got time yet to check it yet.
    Last edited by Fen; 01-04-2015, 07:48 PM.

    Comment


      #3
      I've seen the thread but I haven't read through it all the way.
      Movable Widgets

      Comment


        #4
        thanks Hakabane this is very helpful

        I have one question, what use the "DialoqueWidget" in the DialogueSystem for a Actor?
        reference
        http://dirty-windows.de

        my blog
        http://ulrichthuemmler.blogspot.com/

        Comment


          #5
          The dialogue widget is just where I design out how my widget will look. You could make it just one widget but I like to break my stuff apart.
          Movable Widgets

          Comment


            #6
            Hey Hakabane,

            Sorry it took so long to take a look! I had a look over and really like how you have this set up. the only question I have is how easy is this to edit for individual npc options? Do you have the variables set up to where they can be independently editable? This is an awesome system and if I get the time I'm going to run through and set this up on my own to see where my tutorial can be improved!
            Adam Davis | Marketplace Support | Epic Games
            How to report a bug? | Installation & Setup issues? | Answerhub Bug Reports | Twitter

            Comment


              #7
              i dig this system for its simplicity! well done, hakabane and thx for sharing!

              @adam: if im allowed to give you one advice: use screenshots of your blueprints with only the important things written down, instead of describing everything in prose...it'll be much easier to follow through and much much less error prone! and its prolly faster for you to write and update... ^^

              Comment


                #8
                Honestly it should be pretty easy to edit any part of the NPC but I want to make a GUI for it so it's easier to work with. It would be much easier for people if they could see which options lead where. Kind of like how Blueprints work with the lines between nodes. I really hope to make a better version that with my RPG Template I'm making so that you can activate quests, open shops menus, or other misc options.
                Movable Widgets

                Comment


                  #9
                  Originally posted by Ollinator View Post
                  i dig this system for its simplicity! well done, hakabane and thx for sharing!

                  @adam: if im allowed to give you one advice: use screenshots of your blueprints with only the important things written down, instead of describing everything in prose...it'll be much easier to follow through and much much less error prone! and its prolly faster for you to write and update... ^^
                  Hi Ollinator,

                  I'll definitely take that into consideration, I know I can be a bit long winded . I always welcome suggestions or constructive criticism so I can improve the quality of my tutorials, if you have suggestions please feel free to let me know!
                  Last edited by Adam Davis; 01-27-2015, 11:07 AM.
                  Adam Davis | Marketplace Support | Epic Games
                  How to report a bug? | Installation & Setup issues? | Answerhub Bug Reports | Twitter

                  Comment


                    #10
                    can you upload this as a blueprint component?

                    Comment


                      #11
                      I'm actually reworking this currently and connecting it to a quest system. Converting just the dialog to a BP Component should be simple enough if you follow along with whats above. Once I finish converting all my systems to BP I plan to release them all on here for free. Granted I'm not the best coder so it will need work but it should work enough to get people started.
                      Movable Widgets

                      Comment


                        #12
                        ok thanks for responding. and this is fine, but the first attachment is invalid. unless that is just junk, is that not appearing going to be relevant?

                        Comment


                          #13
                          I'm not sure why the picture stopped loading but I re-uploaded it. it was pretty basic.
                          Movable Widgets

                          Comment


                            #14
                            Hey hakabane , i'm having a problem, that when i choose the first choice, for exemple, it goes to the next screen but the first one doesn't disappears.
                            Thank you very much man!

                            Comment


                              #15
                              Check to make sure you are clearing out the widget's children in the part 1 section. if not it will just add a really long annoying list over and over.
                              Movable Widgets

                              Comment

                              Working...
                              X