Search Unity

[SOLVED] Header attributes in incorrect order

Discussion in 'Scripting' started by ArachnidAnimal, Apr 3, 2017.

  1. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,803
    Using the Header attribute, sometimes the header appears in the incorrect order in the inspector window.
    I have this:
    Code (csharp):
    1.  
    2.     [Header("Room 902 Controller")]
    3.  
    4.     [Header("Lights with LightTransitionController")]
    5.     [SerializeField] private Light [] realtimeLights;
    6.  
    The inspector shows this:

    header.png
    It shows the headers are not in the same order.

    Is this a bug, or am I doing something wrong?
     
    Vivien_Lynn likes this.
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Anything in [] like that is an Attribute, meaning that it applies to the member variable that follows it, just like "private" and "public" are as keywords. So, both your headers there are being applied to the realtimeLights member, and they're just sort of being applied to a "pile" of attributes that apply to that member. So their order won't be predictable, if they're on the same variable.
     
    Bunny83 and guneyozsan like this.
  3. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,803
    Vivien_Lynn, guneyozsan and Ninquiet like this.
  4. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Just another long-standing bug at unity.

    Workaround is to explicitly give the "order"

    [Header("Enter data here", order=0)]

    [Header("Put heights here", order=1)]

    etc.

    There are (obviously) various other bugs - example, you can't "end with a header".
     
    NextVertex likes this.
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    I don't think it is a bug. AFAIK, there's no way to retrieve an actual attribute order from the property in code via reflection.
     
    Bunny83 likes this.
  6. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    @xVergilx - fair enough. But, hmm; any inspector variables you put in there do appear in the same order as in the script.
     
  7. ZRcil

    ZRcil

    Joined:
    Dec 23, 2022
    Posts:
    1
    Im new in unity and im confused because when I try to upload the unity build to the meta quest alpha version, it says that " no END header found" so can you guys please help me with this?