• 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
2
Question by _Amael_ · Aug 20, 2012 at 08:30 PM · inspectorcustom class

An array of custom objects - how do you make their properties show in the inspector?

I have a custom class called "SlotData" that's used to hold a certain set of variables. The variables in this class need to use setter & getters as I need to trigger an update in my code if any of the variables in instances of the class are changed:

 [System.Serializable]
 public class SlotData
 {
     private RosetteController parent = null;

     private int _cycleEvery = 0;
     private Material _replaceMaterial = null;
     private GameObject _replacePrefeb = null;
     
     public int CycleEvery {  get{ return _cycleEvery; }  set{ _cycleEvery = value; if ( parent != null ){ parent.UpdateRosette(32); } }  }
     public Material ReplaceMaterial {  get{ return _replaceMaterial; }  set{ _replaceMaterial = value; if ( parent != null ){ parent.UpdateRosette(32); } }  }
     public GameObject ReplacePrefeb {  get{ return _replacePrefeb; }  set{ _replacePrefeb = value; if ( parent != null ){ parent.UpdateRosette(32); } }  }
     
     
     public SlotData( RosetteController rosette )
     {
         CycleEvery = 0;
         ReplaceMaterial = null;
         ReplacePrefeb = null;
         Parent = rosette;
     }
     
 }


I need to use an array containing instances of this custom class in my main controller:

 public class RosetteController : MonoBehaviour
 {
     
     ...
     public SlotData[] slots; 
     ...
 
 
     void Start()
     {    
         ...
         
         slots = new SlotData[15];
         
         for ( int i = 0; i < slots.Length; i++ )
         {
             slots[i] = new SlotData( this );    
         }
 
         ...
     }
 
 }


My question is how do I make the properties of each element in the "SlotData" objects array show in the inspector?

Everything works fine if I don't use setters & getters in the SlotData class, but I haven't found an alternative to trigger an update whenever any of the variables are changed.

I've been butting my head against this problem for days but I've made no progress - I've tried writing my some custom editor code but I'm getting nowhere as there's very little documentation available, and any examples that I find don't quite do what I'm looking for... I've even tried bodging the Expose Properties Wiki script to no effect :(

Is there:

  • any way to force the "nested" custom objects in the array to show their properties in the inspector

  • an alternative to setters that would call a function when a variable's value is changed (asides from constantly checking a series of if statements)

  • any way to let me "hard code" fields for the properties of the objects in the SlotData array using a custom editor script? (there'll only ever be 15 of the SlotData objects in the array)

  • an alternative to using the SlotData class in general?

Many thanks!

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 DaveA · Aug 20, 2012 at 08:42 PM 0
Share

I'm pretty sure their is a mechanism where the editor can let you know a value has changed, it eludes me what that is offhand, will let someone else answer for that.

avatar image _Amael_ · Aug 20, 2012 at 08:50 PM 0
Share

Thanks Dave - even if there's a function built into the editor that will let me know if a value has changed, I'd really need something that would work independently of the inspector in the long run... i.e. if the package is published to the webplayer and a user changes variables via a GIU, I still need the variables to call a function in the main controller class when they're changed

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Aug 20, 2012 at 08:43 PM

See my comment above, but you could also implement Update and have it run in the editor if you like, it will call update so you can check for changes that way. But the callback or whatever is probably better.

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 _Amael_ · Aug 20, 2012 at 08:50 PM 0
Share

Thanks again Dave - have replied to your comment above. I have thought of just using a series of if statements in Update() but I just can't bring myself to do it... it just screams inefficiency & bad practice to me (especially when you'd end up with 60+ variables to check every frame in my case).

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[solved] How to edit an array of custom classes in the Inspector 1 Answer

Child Class not showing in inspector 1 Answer

Set Level inquiry/data from the inspector 1 Answer

Inspector - Show/hide property within custom class using enum 1 Answer

Will renaming a Serializable class wipe its instances in the 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