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 captainoufo · Aug 29, 2019 at 04:13 PM · scriptableobjectdialogueinstancesreference-other-object

Need help designing a dialogue system (or, how could I deal with referencing scene objects in ScriptableObjects?)

Hi everybody, I need some suggestions for a topic I'm tackling.

I want to code the whole thing myself for the sake of exercise and understanding how it works (and possibly have a custom asset I can reuse for my actual future projects), so I'd like to avoid premade assets from the store.

One of the main goals is to be able to compose the dialogues in the editor/inspector without touching Visual Studio once the system is done. Possibly avoiding custom editors additions, as I never done anything like that and it feels maybe a bit too much dealing with two problems at once, both the dialogue system and the custom editor (but if that's the only way, I'm willing to look into that too; please point me in the right direction if that's the case).

Based on that, I already made a skeleton that is nothing fancy but does at least a part of it's job. It's made of two ScriptableObject classes, a DialogueNode and a DialogueOption.

DialogueNode contains a serializable private string[] npcLines, a serializable private DialogueOption[] options, plus public methods that return both.

DialogueOptions is basically the same, except that there is a single string that is of course the player's line, and it has an array of nodes.

The DialogueManager handles the flow of the whole thing by keeping track of the current node, assigning the text to the correct GUI elements and generating the correct amount of buttons for the player from the options array.

As I said it works decently, except that it works only in isolation. In my plans, both DialogueNode and DialogueOption were meant to optionally have attachable conditions that chacked all sorts of other gameplay elements (say, having a certain item in the player's inventory, checking the value of a certain variable held by either the player instance or another object in the scene, etc) and something else that would affect the same things (again, acquiring an inventory item via dialogue, or setting some variables, or whatever) and this is where i got stuck. I thought I could make a series of DialogueCondition derived classes with something like for example

 public class ConditionNPCStat : DialogueCondition
 {
     [SerializableField] private NPC npc;
 
     [SerializableField] private int requiredValue;
 
     public bool IsConditionMet()
     {
         return (npc.whateverVariableINeedToCheck >= requiredValue);
     }
 }

but then I found that I can only drag prefabs in a ScriptableObject instance's inspector, so that was all for nothing. Same for non monobeaviour, base classes. I didn't even try Structs because as far as I know you can't derive them from a base struct, and I need DialogueConditions to be all of the same base type so I can create an array of the base type in the nodes/options (the idea was to have the method that return the private array to check each of the array's entries for any unmet condition, create a second array with only the acceptable entries and then return that one).

Any suggestion? Including throwing this whole thing into the bin and trying another approach, if you can point me in the right direction.

For the TLDR, I'd like to build, if possible, a system where I can drag and drop stuff in the editor, and set fields in the inspector. Dialogue nodes and dialogue options may or may not be available depending on conditions which require to check on stuff that happens in other game systems. I would like to keep each system more or less indipendent so that I can both reuse the dialogue assets in other projects, and avoid breaking everything in case I decide to heavily modify one of those systems.

Also this whole thing derailed my train of thoughts and I didn't even start to tackle the problem of interacting with other gameplay elements via dialogue, so suggestions on that topic would be appriciated too.

Thank you in advance, any suggestion is appreciated!

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

0 Replies

· Add your reply
  • Sort: 

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

181 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 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 do I decide which Conversation to start when clicking on an NPC? 0 Answers

Different methods for instances of a ScriptableObject 0 Answers

ScriptableObject not Serializing? 0 Answers

Can't you add tags using a script instead of tagging it through the editor ? 1 Answer

Keep data created at runtime in ScriptableObjects? 1 Answer


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