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 /
avatar image
0
Question by anthonyjnrmeyer · Jan 27, 2020 at 05:05 PM · unityeditorserializable

Accessing the public variables from the inspector of a class within a public List?

Hey guys,

Apologies for another new guy without much clue what he's doing. I'm trying to implement a very simple dialogue system and I'me using a Sentence class which contains a string for a sentence and an int to indicate where the sentence is being spoken from in the scene.


Then I'm using a Dialogue class which is simply a List of 'Sentence' class objects.


The Dialogue class is attached to an interactable game object and I'd like to input values for the int and string of each 'Sentence' class object in the inspector of the 'Dialogue' component. is there any way to do so?


Dialogue class:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Dialogue : MonoBehaviour
 {
     public List<Sentence> sentences;
     // Start is called before the first frame update
 }

Sentence class:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class Sentence : MonoBehaviour
 {
     public int dialogueOrigin;
     public string sentence;
 }

What I'm currently seeing in the 'Dialogue' component: alt text

dialoguescript.jpg (35.1 kB)
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 lordlycastle · Jan 27, 2020 at 05:10 PM

This will not be possible without with stock unity inspector as lists store references to the objects.

If you want it to work this way then you Sentence class needs to Serializable and not MonoBehaviour.

There are other ways to achieve this btw, just nothing quick and simple built in Unity. E.g. I use Odin Inspector and that can show the fields in a list. I'm not affiliated with this product, just <3 it a lot. alt text


image-19.png (30.6 kB)
Comment
Add comment · Show 1 · 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 anthonyjnrmeyer · Jan 27, 2020 at 05:17 PM 0
Share

Fantastic. Quick fix, thanks so much!

If anyone reads this in future I used the following thread: https://answers.unity.com/questions/23734/need-to-serialize-a-monobehaviour-class.html to make my 'Sentence' class Serialisable and now I have access to the containing variables from my List in the Dialogue Class.

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

120 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

Related Questions

Creating a Grid Component in the Inspector 0 Answers

how to run unittest in batchmode on mac? 0 Answers

Can using many lights in single scene put load on Unity? 0 Answers

How to open an asset with the current unity version opened? 0 Answers

Stuck at Unity package manager starting server 0 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