- Home /
Why do Inspector headers with comma-separated variable declarations cause redundant headers?
if I use the following code when declaring my variables at the top of my script:
[Header("REFERENCE")]
public Transform trans, camTrans = null;
public G g = null;
protected Rigidbody rb = null;
protected Animator anim = null;
It creates a second "REFERENCE" header after the trans reference in my inspector: ...but if I take away the comma and put both transform references on the same line or put a single-line declaration before them like this:
[Header("REFERENCE")]
public G g = null;
public Transform trans, camTrans = null;
protected Rigidbody rb = null;
protected Animator anim = null;
It works like I want and keeps all these items together under the same header. Does anyone know if there's a way around this? I'm very strict about the organization and order of my variables and would like the transforms first, on the same line, separated by commas. Thanks!
Answer by DavidMontoyaJD · Jul 20, 2021 at 02:02 PM
For me it was very annoying because I had several variables declared with commas:
[Header("--------- Icons")]
public Sprite fruit, lightingBall, give5Plinkos, make10Coins, drop15PlinkosIn10Seconds, drop20Plinkos, make20Coins, SevenTex, give2Dollars, give20Dollars, give200Dollars;
which made the editor look like this:
I noticed that if I declare the first variable alone and the rest separated by commas, Unity understands it and shows it in the right way:
[Header("--------- Icons")]
public Sprite fruit;
public Sprite lightingBall, give5Plinkos, make10Coins, drop15PlinkosIn10Seconds, drop20Plinkos, make20Coins, SevenTex, give2Dollars, give20Dollars, give200Dollars;