- Home /
Header and Serialized Fields
Is it possible to have a single header with a single serialized field that applies to multiple variables of certain range?
Something like this, but without having to declare 3 separate serialized fields and 3 separate variables in 3 lines: ![alt text][1]
The code I have right now:
[Header("Camera Settings")]
[SerializeField, Range(1f, 20f)]
float xAxis = 5f;
[SerializeField, Range(1f, 20f)]
float yAxis = 5f;
[SerializeField, Range(1f, 20f)]
float zAxis = 5f;
Answer by Eno-Khaon · Jul 23, 2021 at 01:25 AM
Just as you can declare multiple variables in a single line, you can also apply attributes to them at the same time.
[SerializeField, Range(1f, 20f)]
float xAxis = 5f, yAxis = 5f, zAxis = 5f;
While this is true, his issue is that he can not also use the Header attribute since that would also apply to all 3 fields. So instead of one Header he would have 3, one on each field. It's not possible to treat the 3 variables as one thing and seperately at the same time, at least from an attributes point of view.
The best solution may be to use a custom serializable class or struct like this
[System.Serializable]
public class CamSettings
{
[SerializeField, Range(1f, 20f)]
float xAxis = 5f, yAxis = 5f, zAxis = 5f;
}
[Header("Camera Settings")]
public CamSettings camSettings;
Of course this will make the cam setting being collapsable. In this case you may not need the header at all?!
Your answer
![](https://koobas.hobune.stream/wayback/20220613040658im_/https://answers.unity.com/themes/thub/images/avi.jpg)