Use Unity Attributes to Optimize Your Game Design Workflow
Save yourself some time in your next game dev project and use attributes to organize and assist!
![Unity Logo with [Attributes]](https://miro.medium.com/max/60/1*UunhSAsrWsVDmd4gBdNH4g.png?q=20)
Continuing in my series of productivity and organizational tips for Unity, I want to present some Attributes that will make your game designer happy beyond words! For those that don’t know, Attributes in C# are tags that help you associate metadata to constructs like classes, functions and variables.
Attributes are a C# feature (that can be found in most other OOO languages as well) but they are especially powerful when used for Unity. If you are mostly in Visual Studio most of the day, you are a game developer. If you are in the Unity IDE more than Visual Studio, you are also a game designer. Designers need developers to build tools to help them with their workflow in Unity, and Attributes are some of the greatest tools to help designers out.
You may be aware of some of these Attributes, but I’m sure there are a couple that you can integrate into your development routine to improve your Unity experience!
1. [HelpURL]
If you’ve ever used the little Docs icon next to each pre-defined component in Unity, you might find this one necessary. Create a link to your own help documentation by adding the [HelpURL] attribute at the top of your class.

[HelpURL("https://cjames1.medium.com/")]public class Enemy: MonoBehaviour{}
2. [DisallowMultipleComponents]
To prevent users from adding more than one of the same component to a Game Object, you can add the [DisaalowMultipleComponents] attribute to the top of your class.
[DisallowMultipleComponents]public class Enemy: MonoBehaviour{}
3. [RequireComponent]
This attribute forces you to have other components that you specify on the Game Object. If they are not there, they are automatically added when you add this script as a component. Think of all the times when you forgot to add a Rigidbody or Collider to your object — this will prevent that from happening.
[RequireComponent(typeof(Entity))]public class Enemy: MonoBehaviour{}
4. [Header]
Possibly the most well-known attribute, [Header] allows you to specify headers in the Inspector so you can organize your variables. Very straightforward — and very useful.

public class Enemy: MonoBehaviour{
[Header("Stats")]
public int maxExp;
public int health;
public int maxHealth;
}
5. [Range]
Let’s say you have a float that should only exist between 0 and 1, or an int that goes from 0 to 100. You can force this clamping in the Inspector with the [Range] attribute.
public class Enemy: MonoBehaviour{
[Range(0, 100)]
public int maxExp;
public int health;
public int maxHealth;
}
6. [Tooltip]
If you want some helpful text to appear when the designer hovers their mouse over a variable, you an add the [Tooltip] attribute with the text as a variable. Your designer will thank you!
public class Enemy: MonoBehaviour{
[Tooltip("Defines the maximum experience for enemies")]
public int maxExp;
public int health;
public int maxHealth;
}
7. [HideInInspector]
Sometimes you need a public variable but you don’t want it to be edited in the Inspector. This can be achieved with the very straightforward [HideInInspector] attribute.
public class Enemy: MonoBehaviour{
public int maxExp; [HideInInspector]
public int health;
public int maxHealth;
}
8. [SerializeField]
The reverse of (7) can be done as well — if you have a private field that you would like edited in the inspector, just add the [SerializeField] attribute.
public class Enemy: MonoBehaviour{
public int maxExp;
public int health; [SerializeField]
private int maxHealth;
}
9. [Space]
To add a small space between variables in the inspector, use the [Space] attribute. Quick and easy!
public class Enemy: MonoBehaviour{
public int maxExp;
public int health;
private int maxHealth; [Space] public long id;
public string enemyName;
public string longDescriptionText;
}
10. [TextArea]
Have you ever had a text field that is too small for the input and clips everything you are typing in the Inspector? You can change the field to a text area with the [TextArea] attribute.

public class Enemy: MonoBehaviour{
public long id;
public string enemyName; [TextArea]
public string longDescriptionText;
}
11. [UnityEditor.MenuItem]
Last one for good luck! This one is a bit of a doozy. the UnityEditor namespace allows you to write Editor level functionality into your scripts. This is great for testing, creating macros for designers, and streamlining the design phase.
This attribute allows you to use a function in this script in the Editor as a single menu item click. In the example below, let’s say that some enemies have their color set to transparent. We can create a function that changes all enemies back to being opaque within the top menu of Unity, using this function. Think of the possibilities for this one!
public class Enemy: MonoBehaviour{ [UnityEditor.MenuItem("Utils/Enemies/Appear All")]
public static void AppearAll(){
var enemyList = FindObjectsOfType<Enemy>();
foreach(GameObject e in enemyList){
e.GetComponent<SpriteRenderer>().color = Color.white;
}
}}
Here is an example of all of the attributes we wrote combined into one script. Feel free to use this whenever you need a refresher on the common attributes you have at your disposal!
Conclusion
And there you go! If you use even half of these attributes in your scripts, you will have a much easier time designing your game in Unity. Give some of them a try!
Are you a prospective indie game developer? Do you sometimes wish you could release your very own dream game? Well wish no longer! Here are some articles that will give you the power to go out and start your project.