• 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
0
Question by Fire-Dragon-DoL · Jan 11, 2012 at 09:27 PM · editorinspectorcustom-inspectorcustom-editor

Inspector: custom property with custom type use default editor

It's hard to give a title for this question, sorry for this.

My situation is this: I have a script that should set a property called "Monsters" (a list) on a given gameobject. This list is composed by a lot of Spawnable, wich is a simple class built in this way:

 public class Spawnable : MonoBehaviour
 {
     public uint Amount;
     public bool Respawn;
     public GameObject Monster;
 }

So the Spawner script that is attached to my "Spawn" empty gameobject (a prefab):

 public class Spawner : MonoBehaviour
 {
     public List<Spawnable> Monsters;
 }

Are there any possibility to do this by allowing unity to automatically generate the editor for my custom type with its base editors? (one for int, one for bool and one for gameobject). Are there any way to set everything I've shown in the inspector?

Thanks for any suggestion I would like to edit through the inspector my monsters list by setting its size (this is already possible) and set Spawnable properties for each item.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by syclamoth · Jan 11, 2012 at 09:55 PM

Yes, it's very straightforward-

Your 'simple class' shouldn't be descended from MonoBehaviour. The MonoBehaviour class is a complex class with lots of functionality, and it's not really intended to work that way. Instead, just use the 'System.Serializable' attribute, and make it a base class.

 [System.Serializable]
 public class Spawnable
 {
     public uint Amount;
     public bool Respawn;
     public GameObject Monster;
 }


Then, when you create your public list, it will give you a sizable dropdown-list with the correct properties for the type.

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 by0log1c · Jan 11, 2012 at 10:04 PM 1
Share

Correct! Data class shouldn't inherit from $$anonymous$$onoBehaviour. They should be made as base class or you may want them to inherit from Object or ScriptableObject, which are explained in the Scripting Reference.

avatar image Fire-Dragon-DoL · Jan 11, 2012 at 10:37 PM 0
Share

Your example is great and works really way, thanks a lot! (also to you Byologic). I used the $$anonymous$$onoBehaviour only because it was the only way I know to make something appear in the inspector, I'm more happy with this approach keeping inheritance for other important things :)

avatar image
1

Answer by by0log1c · Jan 11, 2012 at 09:59 PM

If you are not using custom inspector script then I believe all you need is the Serializable attribute.

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
0

Answer by jarenas · Mar 27, 2013 at 01:31 PM

Hi,

And... what is the answer if I need Spawnable class like Monobehaviour?. I have the same problem and, in my case, I need to detect mouse behaviour over the element. I mean, imagine I have a GUI and a MenuPage and I have a list of controls, basically, this controls are buttons and I have a MenuButtonGUI class for it. Then, like Monster class, I have a MenuPage class to containing a List. When I write a sise in the list I watch a new element in the list but I cannot setup its properties. I have a "class MenuButtonGUIEditor : Editor" too and I tried with it to show and edit the properties of the buttons inside the MenuPage class without success. I have created a "class MenuPageEditor : Editor" to edit the properties of all, the MenuPage class and the properties of elements in the MenuButtonGUI list as well but it seems it's not the way.

Any Idea?

Regards, Jordi

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 whydoidoit · Mar 27, 2013 at 01:34 PM 0
Share

Please don't post questions as solutions - this is not a message board.

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

How should I serialize data that is also editable in the Inspector? 2 Answers

How do I change inspector values of other game objects using a custom Editor Window 0 Answers

Custom Inspectors for generics and tweaking default inspectors 1 Answer

Custom editor tags not saving 1 Answer

TerrainToolkit build errors 2 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