Search Unity

Utilizing JSON for dialogue, can anyone help?

Discussion in 'Scripting' started by FeldIV, May 5, 2020.

  1. FeldIV

    FeldIV

    Joined:
    Dec 16, 2018
    Posts:
    27
    Hi all,

    I'm still a relative beginner in Unity getting my feet wet, and I'm interested in learning how to code dialogue like you'd see in many games such as RPGs (or dialogue in narratively driven games in general, such as Deus Ex, etc).



    I've been following a dialogue tutorial by Brackey and someone pointed out that a JSON setup is ideal as opposed to storing the dialogue on an object itself attached to a script. I've heard about this before, but I'm unsure how to do so; how do I utilize JSON for for the purposes of storing dialogue externally? Other than not using JSON, I rather like Brackey's setup, even better, is there a way to incorporate this within the framework that Brackey used?

    Thanks all! For reference, here's the tutorial and affiliated code/scripts;

    https://github.com/Brackeys/Dialogue-System
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    I think if you're a beginner, you should just go with what works easily and use the system in Brackeys' video if it's working for you. Don't fix what ain't broke.

    If it starts becoming very difficult to manage the dialogue strings, then start thinking about ways to make that easier.
     
  3. FeldIV

    FeldIV

    Joined:
    Dec 16, 2018
    Posts:
    27
    If it comes down to it, sure, but this is more of a learning experience than me deadset on wanting to make a game right now; if JSON is indeed the optimal way to do things (and it's looking to be so; in the future I definitely don't want to put an entire script for a medium or even smallish sized game on Objects) I'd rather start learning it sooner than later.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    What makes you think JSON is the optimal way of doing things? JSON is just a way of structuring data. You could put JSON in your prefabs if you wanted to. Are you talking about including JSON files in your project? A single JSON file with all your dialogue? A JSON file per dialogue? JSON in a database somewhere? JSON on a web server to serve your dialogue? JSON is not in and of itself a solution to anything.

    JSON is a tool, and like any tool you need to size up the problem in front of you before you decide it is the right one. It may well be that JSON makes sense for you, but don't make that decision based on nothing.
     
  5. FeldIV

    FeldIV

    Joined:
    Dec 16, 2018
    Posts:
    27
    Oh, this isn't a decision I've made lightly or arbitrarily, I'm a beginner but only relatively so; I know just enough about storing dialogue and how it's done to know that doing so without externally storing it sounds miserable and when I do eventually make larger games I have no interest in doing so. It's a common method of storing dialogue and I've researched alternatives and I've decided based on the data available that this is what I'd like to learn.

    JSON, or XML for that matter are easy methods for me to write dialogue in Notepad and also opens up options later to translate it, edit it, or proofread it, etc etc.
     
  6. EugeneAB

    EugeneAB

    Joined:
    Dec 6, 2016
    Posts:
    2
    I'm having the same issue right now. I'm not sure on how to build the dialogue system for my game.

    I would assume topic here is more about separating dialogue text from c# scipt as TextAsset. json here is a format of storing the data, it could be a csv, xml, yaml etc. Am I right @FeldIV or did I understand your question wrong? Have you found any more information regarding this topic? What aproach did you chose?

    The benefit I see here is that you can write dialogues that then can be imported straight to the engine. This should also make translation easy.