Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
4
Question by xEnOnn · Oct 04, 2012 at 05:45 AM · c#inspector

Show custom List in Inspector?

I have tried using a usual `List` as a public class variable and the `List` shows up as one of the variables in the Inspector when the script is attached to a `GameObject`.

I created my own List called `MonsterList` by extending the `List` so that I could encapsulate some methods to my `MonsterList`. However, any public class variable of the type `MonsterList` doesn't show up in the Unity Inspector for me to set a size and drag to assign GameObjects to `MonsterList`.

So, how can I get a custom List to show up in the Unity's Inspector?

PS: I am using C#.

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
11
Best Answer

Answer by Voronoi · Dec 01, 2014 at 06:14 PM

You can do this by making your Custom class Serializable:

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class Item
 {
 
     public string         itemName;
     public int             itemID;
 
     [System.Serializable]
     public enum ItemType
     {
     Mammal,
     Bird,
     Fish,
     Insect,
     Reptile
     }
 
     public Item (string name, int id)
     {
     itemName = name;
     itemID = id;
 
     }
 
     public Item() {
     }
 }


Then, when you add this class to another script, even as a List it shows up in the Editor along with items added or subtracted.

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 ClearRoseOfWar · Sep 13, 2016 at 03:25 PM 0
Share

As simple as the answer was, Thank you so much!

avatar image LukeNukem44 · Jun 21, 2018 at 08:33 AM 0
Share

In this example, the two public member variables are all that show in the inspector. What is the point of the enum which is never displayed and the constructor which is never called with arguments??

avatar image aaronshawcsh · Jun 01, 2020 at 08:40 AM 0
Share

@LukeNukem44 There isn't too much of a point, except that if you also add a public variable of type "ItemType" in the public variables, you will then be able to have that as a dropdown in the Inspector Window.

Hope this answers your question - I do realize it's a bit late :)

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

16 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Inspector cannot find script instance 1 Answer

c# enum wont show in inspector 3 Answers

Javascript and C#, different behaviour in inspector ? 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