Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by GarbagePile · Feb 13, 2018 at 04:41 AM · uitextrpgdialoguetextasset

Best Practice For Storing RPG Dialogue?

I am working on an RPG dialogue system where each dialogue line consists of the actual dialogue being spoken, the name of the speaker, and a facial expression for the speaker, if applicable. I have done this by creating the following Dialogue class and creating a public Dialogue list within a DialogueHolder class, allowing me to edit dialogue within the editor.

 [System.Serializable]
 public class Dialogue {
     public string name;
     public Sprite emote;
     [TextArea] public string line;
 
     public Dialogue(string n, string l, Sprite e)
     {
         name = n;
         emote = e;
         line = l;
     }
 }

However, on a previous project, I used a different approach for storing dialogue. I used a struct, named DialogueLine, instead of a class, and loaded each line from a text file, using semicolons to separate information.

 public void LoadDialogue(TextAsset textToLoad)
     {
         int i = 0;
         string[] textLines;
 
         // Separate the text into lines
         textLines = (textToLoad.text.Split('\n'));
 
         // Add each line to the list
         do
         {
             string[] lineData = textLines[i].Split(';');
             DialogueLine lineEntry = new DialogueLine(lineData[0], lineData[1], lineData[2][0]);
             lines.Add(lineEntry);
             i++;
         } while(i < textLines.Length);
     }

What I want to know is which of these two methods is better: storing dialogue within the editor or using external text files and reading them in. I can already see some pros and cons of each approach in regards to ease of use, but is there something I'm not factoring in (i.e. performance) that should convince me to chose one over the other?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Harinezumi · Feb 13, 2018 at 10:52 AM

Depending on the size of the project, if it is really small, then just set up dialogues from the editor. In any other case, you will have benefits from loading the dialogue from a resource file (even in case it is small, but then it might not be worth the extra effort).
But what I would do is to make a mixed system: being able to set up from the Editor, but being able to override the setup from the text file. That way you will get the flexibility of quickly changing, testing things if needed, but also the advantages of defining from a text file.

As for using class or struct, there is not much difference between them except for a class being a reference type (can be null, can be modified when passed as normal parameter), while a struct is not.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GarbagePile · Feb 13, 2018 at 01:59 PM 0
Share

What would constitute a small project? Do you mean the number of people working on it, which in this case is just me, or are you referring to the length of the game itself?

avatar image Harinezumi GarbagePile · Feb 13, 2018 at 02:14 PM 0
Share

The length of the game, the number of scenes, but I think the amount of dialogue texts is the best measurement in this case. So if you have only a few dialogues (maybe not more than 30 lines - but this is just my "measurement"), then don't worry about setting up loading it from file. Anything above that I think you would benefit more from it (in the long run). And if you make it general enough, maybe you can reuse it in another game, or even sell it in the asset store ;)

avatar image GarbagePile Harinezumi · Feb 14, 2018 at 01:49 AM 1
Share

So I ended up creating a system that implements both methods like you said. I check for a public TextAsset in Start(), and if it isn't null I replace any publicly set dialogue with the data from that TextAsset. It loads the name and dialogue properly, but I haven't implemented anything for the facial expressions, as I was previously setting them using public Sprites. What I plan on doing is putting all of my facial expressions into an array, and then reading an index from the text file (i.e. if Happy Boy's face is at index 2 in Sprite[] faces, then use 2 as the face parameter for Happy Boy's lines).

Thank you so much for the help!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

133 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to reset NPC dialogue? 0 Answers

Encyclopedia System 1 Answer

Is it possible to call a variable (i.e. int) from a text variable ? 0 Answers

Adding Text to Prefab 0 Answers

MissingReferenceException: The object of type 'Text' has been destroyed but you are still trying to access it. 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges