Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Need Help understanding how to implement a Dialogue System.

Discussion in 'Scripting' started by Gingerbread84992023, Sep 2, 2020.

  1. Gingerbread84992023

    Gingerbread84992023

    Joined:
    Jul 27, 2018
    Posts:
    6
    So for the past couple of days, I've been attempting to implement a functional dialogue system into my project where the player can select choices for some parts of dialogue. I've looked into tutorial after tutorial and it feels like with every tutorial I watch the more frustrated I get. I've taken the possibility of going down a route that includes scriptable objects. So far I know how to make a scriptable object but I'm not exactly sure how to implement scriptable objects in code. For example, if I were to make a conversation I don't know how to make the conversation start nor how to display it onto a dialogue box for the player to see.

    By the way, I'm not asking for plugins/unity store things. I'd rather learn how to do this myself and receive an explanation that can help me understand it better.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,345
    Let me give you a helpful framework to think about the problem. Let's talk broadly about the main objects, since we have all used dialog systems.

    First, there's the individual lines. These are just strings, obviously, so putting them in a ScriptableObject is certainly reasonable.

    Next there's the notion of a given choice (node), such as:

    Actor 1: "Where do you want to go?"
    Actor 2: (the player) can respond:
    -> "To Work"
    -> "To Home"
    -> "I am staying here."

    Now we need the notion of how those are combined to present a given dialog, so we'll call that the "network" or the "tree" of choices.

    Those three notions can be easily represented in static form in ScriptableObjects, linked either by some identifier, or else with references dragged into each other.

    Now you need a manager that can process the network, and wait at each choice (node) for the response, then look in the network to decide where to go next based on input.

    The manager can also present the current choice to the user, but it might be cleaner to just have a separate thing that presents it to the user, and also accepts input and passes it back to the manager. That way the PC version might accept input from a keyboard, but the console version would read a controller up/down and ACCEPT, for instance.

    Does that help you reason about the parts you might need?
     
  3. Gingerbread84992023

    Gingerbread84992023

    Joined:
    Jul 27, 2018
    Posts:
    6
    I understand the implementation of the individual lines as well as the manager to a certain degree. Although I did get a little lost on your explanation of implementing choices, by implementing them as statics what exactly do you mean by that? I know that static is a descriptor for certain variables (like public static bool for example) but I haven’t heard of any other version of it.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,345
    The term "static" I use up there is not the same context as coding. I mean "static" inasmuch as the dialog does not customize itself dynamically based on game state, such as "you get an extra option to decide you want to go to atlantis, but only if you have a submarine in your inventory." That's what I meant by static: an unchanging blob of predefined data (which is exactly what ScriptableObjects are good for) that plays the same regardless of dynamic game conditions.
     
  5. Gingerbread84992023

    Gingerbread84992023

    Joined:
    Jul 27, 2018
    Posts:
    6
    Okay, that makes sense, so if I'm thinking about this right I'd need a scriptable object listing the name of the character speaking and the sentences. then in a separate (or in the same) scriptable object I'd have to have the dialogue options as a list?? Then after that, I'd need a dialogue manager. Am I interpreting this right?
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,345
    Sounds reasonable... if that sounds like too many parts, just write it as a single MonoBEhavior with some container objects inside it for the data, write some code to dynamically create a simple dialog tree one time, and at least get the fundamental sequencing of the thing working properly FIRST. Then you can refactor the data sources and pluck them out to ScriptableObjects. That keeps it initially simple for you, all in one place. It is SOFT ware after all, which implies that it is SOFT and can be changed. :)