• 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
Question by 3tai · Sep 09, 2016 at 09:02 PM · inspectorclassdisplayserializeinherit

Serialize inherited List class, to display in Inspector

I am creating a custom class based on List and want to set it so that it displays in the inspector just like an ordinary List would.

 public class CimManager : MonoBehaviour {
     [System.Serializable]
     public class CimList : List<string>
         {
         //some methods and accessors here, but no variables
         }
 }

in another Monobehaviour:

 public class TenantClass : MonoBehaviour {
         public CimManager.CimList occupants = new CimManager.CimList();
 }

I have TenantClass attached to a GameObject, and when inspecting the GameObject I see the Occupants field in the inspector, but there is no option to choose its length nor is there a dropdown arrow to expand the list to enter in my own values. This is also the case when I know that the CimList already is populated.

Screenshot

I want it to display the way Rates does (which is a float[] )

I know one workaround is to define TenantClass.occupants as a standard List and cast it to my CimList class whenever I need the extra functions, but is there a more proper way of doing this?

Unity 5.3.1f1

occupantsinspector.png (3.1 kB)
Comment

People who like this

0 Show 4
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 Sergio7888 · Sep 10, 2016 at 07:36 AM 0
Share

try use


[SerializeField]
private List occupants = new List();
public CimManager.CimList Occupants { get { return new CimManager.CimList (occupants); }  }
An use "Occupants" not "occupants" in your code after use do this:

 ocupants.Clear();
 ocupants.AddRange(Ocupants);

avatar image 3tai Sergio7888 · Sep 10, 2016 at 05:51 PM 0
Share

I can't do this because getting Ocupants returns a new instance of the occupants list. I need to be able to access it directly. Doing things like Occupants.Add(newOccupant) doesn't affect the private occupants list. This is really work-around-y anyway, I am more looking for more documentation regarding serialization for unity inspector so I can do it properly.

avatar image Sergio7888 3tai · Sep 10, 2016 at 06:00 PM 0
Share

Can you use a standtard list and create Extension methods for the list class

Show more comments

0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

69 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

Related Questions

Custom inspector for items in array 1 Answer

How to create a drop down menu in editor inspector 0 Answers

UNET Commands calling advice. Calling Commands from CHILD object 1 Answer

Is this true? 1 Answer

Best way to communicate between scripts 4 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