Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Hide field in list?

Discussion in 'Editor & General Support' started by CatchFires, Jan 19, 2021.

  1. CatchFires

    CatchFires

    Joined:
    Jul 19, 2020
    Posts:
    38
    In the inspector, if you have a list of a class that has fields, the list will show all public fields right?

    is it possible to hide certain values of a list conditionally?

    for instance

    I know in editor scripting, you can use a bool to hide fields, just not sure if or how its possible for the lists.

    Example;

    ListExample1.png



    ListExample2.png
     
  2. PixelPrime11

    PixelPrime11

    Joined:
    Mar 19, 2017
    Posts:
    14
    Try adding
    [HideInInspector]
    above your public class member.

    Code (CSharp):
    1. [HideInInspector]
    2. public string TestString;
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    I think you need a custom property inspector for this. It would just have code that checks the quantity and displays the sub-fields (or not). I think those work even when embedded in lists but I haven't done it recently enough to be sure.
     
  4. CatchFires

    CatchFires

    Joined:
    Jul 19, 2020
    Posts:
    38
    @PixelPrime11 That would permanently hide it.

    @Kurt-Dekker I did make an inspector script for the TestList class and didn't call the base OnGUI function, so none of the values would have shown up, but when in a List they do, so I imagine you'd have to do a custom property drawer for List, but how to do it as List<TestList>. I'm not sure
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    Are you saying you made a custom property drawer for TestList class and it works as expected, but when you look at a collection of them it reverts to the default inspector for the TestList class?

    That seems counter to my remembrance of it but it's been a while.
     
  6. CatchFires

    CatchFires

    Joined:
    Jul 19, 2020
    Posts:
    38
    @Kurt-Dekker
    No, I made a custom inspector script for TestList and didn't call base ongui, not a property drawer, but now that you say that, I think you're right, make a property drawer for TestList.

    The logic in my head was that the property being drawn was the list itself and thought I might have to make a custom list propertydrawer.

    I'm gonna go play around with the Test List propertydrawer
     
    Kurt-Dekker likes this.
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Pretty sure you just need a custom property drawer for TestList, or whatever the type the list contains. Then it will show up the way your property drawer dictates regardless of whether it's part of a list or not.
     
    Kurt-Dekker likes this.