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 /
avatar image
1
Question by corn · Apr 28, 2017 at 10:21 AM · serializationcustom editorpropertyfield

PropertyField for a list marked with [HideInInspector]

I want to hide a list in the inspector and show it only under specific conditions.

 [SerializeField, HideInInspector]
 private List<int> _myList = null;

In my custom editor, I then try to show the property field.

 SerializedProperty serializedProperty = serializedObject.FindProperty("_myList");
 EditorGUILayout.PropertyField(serializedProperty, true);

However, even though I set includeChildren to true, it shows the name of the property, but nothing else (size or children).

Is there a way to make this work ?

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
1

Answer by Adam-Mechtley · Apr 28, 2017 at 10:42 AM

If you have a custom editor where you are controlling the conditions under which it is displayed, why do you need the HideInInspector attribute on it?

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 corn · Apr 28, 2017 at 10:52 AM 0
Share

Because I want to have it hidden by default. If the condition is met, I'll show it in OnInspectorGUI. But drawing all the propertyfields of my object by hand is tedious, I'd rather only override the behaviour only for specific properties.

Edit : Just to be clear, my problem is not "How can I show or hide a list under specific conditions", I have other ways of doing that if need be. I just need to know if there is a way around this specific HideInInspector issue. If there's not, I'll implement this another way.

avatar image Adam-Mechtley corn · Apr 28, 2017 at 12:28 PM 1
Share

Understood; so it sounds like you draw the default inspector and then only implement special conditions for ones that are marked as hidden by default.

The problem is that the default drawer used by EditorGUI.PropertyField() iterates through children using SerializedProperty.NextVisible() rather than SerializedProperty.Next(), which in this case will pick up nothing since the parent property is not visible.

avatar image corn Adam-Mechtley · Apr 28, 2017 at 01:04 PM 0
Share

Right, that makes sense. I guess I just have to iterate on the child properties myself and draw a property field for each child then. Thanks for the explanation !

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

69 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving editor-only variables 0 Answers

Serialization with custom editor, prefab not saving (again) 1 Answer

Displaying System.objects not serialized by Unity in a Custom Editor 0 Answers

How to create a new SerializedProperty? 0 Answers

Invalid iteration - (You need to stop calling Next when it returns false) 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