Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 gyrosp · Aug 02, 2015 at 02:27 AM · listinspector

Editing a List<> in Inspector

Hi.

I have a class with a List<> and I'd like to be able to edit this list in the inspector. I'd like to be able to add, alter and delete objects in this list.

Unfortunately the inspector only show the size of the list but not the objects itself. If I use an array instead of List<> I can edit the items even thow I could not add or delete items.

These are my classes:

 public class DamageManager : MonoBehaviour
 {
     public List<DamagerLevel> lstDamagerLevels;// = new List<DamagerLevel>();
     public DamagerLevel[]  TestWithArray = new DamagerLevel[5];

 }

 [System.Serializable] 
 public class DamagerLevel
 {
     public float neededDamageInPercentage = 50f;
     public Sprite damageSprite;
 }

This is what it looks like in the inspector:

alt text

So, how can I make my List<> editable in the inspector and add or delete items like a Button in the UI can?

alt text

Many thanks in advance!

1.png (17.5 kB)
2.png (8.5 kB)
Comment
Add comment · Show 2
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 gyrosp · Aug 01, 2015 at 11:25 AM 0
Share

I googled a lot and found nothing yet. This is the reason why I asked the question here.

I thought that this would be a native behauvior of the inspector to allow editing lists and that I might be missing something obvious.

If I have to create my own editor-script please just tell me and I'll dig deeper into this.

Edit:

I found several posts that indicate that generic lists should work with the inspector by default like here: http://forum.unity3d.com/threads/inspector-allow-us-to-edit-generic-lists-and-dictionaries.174790/

But why does this not work in my case?

avatar image Eric5h5 · Aug 02, 2015 at 03:50 AM 1
Share

I copied your DamagerLevel class, then did public List<DamagerLevel> blah and it shows in the inspector just like an array.

4 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by RicoLoco · Jul 24, 2016 at 06:43 AM

use [System.Serializable] to serialize your DamagerLevel class and then it will show up. oops, I see now that you did.

Comment
Add comment · 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
4

Answer by IronarmGames_LLC · Jul 24, 2016 at 05:46 AM

You need to create a custom inspector:

Heres some information on custom inspectors:

  • ) http://docs.unity3d.com/ScriptReference/EditorGUILayout.html

  • ) http://docs.unity3d.com/ScriptReference/GUILayout.Button.html

  • ) http://docs.unity3d.com/ScriptReference/Editor.html

  • ) http://docs.unity3d.com/ScriptReference/EditorWindow.html

But basically in your custom inspector you are going to need to have 2 functions, one for adding a new entry to the list at an index and one for removing entries from the list at an index.

Now what you can do is wire up some GUI.Button as a "+" and "-" symbol to simulate a add and remove button, then basically use a foreach to create a layout containing these 2 buttons for each element in your list. This way, you can have a "+" and "-" button for each element in your list.

You should really look into the custom inspectors and how they function using OnGUI and Layouts.

Comment
Add comment · 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
2

Answer by kunkelbek · Aug 19, 2017 at 03:59 PM

It seems I'm a little late to the party, so I'm assuming this thread is no longer valid. For anyone who is (like me) also searching for a solution to this problem:

What you're looking for is Reorderable Lists.

Sadly Unity has (as far as i know) no documentation on these lists, but I have found another site that explains them very well.

You can find this page here.

hope this helps!

Comment
Add comment · Show 2 · 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 UnityDeveloper2 · Mar 26, 2018 at 09:54 PM 3
Share

Your link is broken, this may be helpful.

avatar image UH4631 · Jan 29, 2019 at 02:40 AM 2
Share

Neither of the links worked for me unfortunately. However, the use of a reorderable list was shown at a Unite talk in 2016. Here's a link to the talk when the list is shown: https://youtu.be/9bHzTDIJX_Q?t=2122 The timestamp is set to where he shows what the list looks like in the inspector, but he shows the inspector code he used about 2 $$anonymous$$utes later.

avatar image
0

Answer by ashleyjlive · Jul 24, 2016 at 03:22 AM

I think you are mistaken. The button GUI is specific for UnityEvents (similar to a delegate) and has nothing to do with a list/array.

Lists are treated exactly the same as Arrays in the GUI (not code). The Add/Remove feature of a list does not exist in the Unity GUI. Instead you can define a size of the list and then fill in the data for each element in that list. Additionally, if you wish to delete a specific element in the list you can right click on it and select remove.

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 DragoDude · Apr 02, 2021 at 09:51 PM 0
Share

Late but it is not exclusive. The button GUI can be implemented, I did it in a few $$anonymous$$utes for my custom cutscene sequencer. It just requires knowing a few things that can be easily learned in a day. Hope this helps anyone who stumbles across it.

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

11 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

Related Questions

A node in a childnode? 1 Answer

Inspector scripting, adding lists, checkboxes and buttons [With Image] 0 Answers

Difference between assigning a value in inspector and with a custom editor script 1 Answer

Adding an item to a Generic List copies the old one 1 Answer

*Really* need help on Serialisation, stuck on this for over a week now, deadline looming 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