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 spaunn · Dec 29, 2015 at 06:19 AM · inspectorcustom inspectornested

How do I get a List or array in a custom inspector?

Hey guys,

I have a Serializable class that has a custom inspector and I need an array or List of it in another class.

This is the class that has a custom inspector, it's much longer, but I've taken a sample to make it easier...

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class StepCheck : MonoBehaviour
 {
     public string vsCharacter;
     public int characterBlade;
     public bool canLose;
     public int stepOnLose;
     public int stepOnWin;
 }

And this is the class that needs to contain a list...

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 [System.Serializable]
 public class Scene : MonoBehaviour
 {
     public List<StepCheck> steps;
 --or--
     public StepCheck[] steps;
 }

I've searched through google and can only find one good answer that dates back to 2013 which doesn't seem to work for whatever reason.

So far, this is all that happens.... alt text

And this is what should be in each of the elements... alt text

I can't work this out for the life of me, does anyone have any suggestions?

Cheers in advance!

ht.png (5.7 kB)
ths.png (6.8 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
0
Best Answer

Answer by Gnorpelzwerg · Dec 29, 2015 at 09:20 AM

It looks like your Element 0 is just not assigned. Do you need to inherit from MonoBehaviour in the StepCheck class? I would recommend you to define it inside the Scene script, if you don't need the StepCheck class outside of it. Displaying a class structure inside a public Collection works fine for me then. Also there is no need to add the [System.Serializable] Attribute to MonoBehaviour classes since Unity displays them automatically. I used this in one of my projects to handle a time controlled in-game console. The class was shown in the editor inside the list. Which was admittedly added at runtime.

   public class Log : MonoBehaviour {
 
     public List< Message > _messages = new List< Message >( );
 
     [System.Serializable ] public class Message {
 
         public Message( string text, float deathtime ) {
 
             _text = text;
             _deathtime = deathtime;
         }
 
         public string _text;
         public float _deathtime;
     }
     ...

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 spaunn · Dec 29, 2015 at 09:25 AM 0
Share

Thanks for the info! $$anonymous$$anaged to get it working as intended, cheers again :)

avatar image Gnorpelzwerg · Dec 29, 2015 at 09:32 AM 0
Share

When i just tried to derive class $$anonymous$$essage from $$anonymous$$onoBehaviour, i got the same issue. The list is not empty, but classes deriving from $$anonymous$$onoBehaviour seem unable to display in the inspector view. Are you adding the StepCheck class instances by searching for a script on other GameObjects with GetComponent( )? If so, I would rename the StepCheck script (if needed as $$anonymous$$onoBehaviour) and define a class without inheritance from $$anonymous$$onoBehaviour inside it as public variable, that contains all the variables you need to display in the inspector.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Custom Editor List with child classes 1 Answer

CustomEditor stops displaying after changing script location 1 Answer

Custom Inspector Script Resetting Information 0 Answers

How do you update a property's int value based on two (or more) other properties in the Inspector? 0 Answers

Target field of a MonoBehaviour attribute ? 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