{"id":15160712,"url":"https://github.com/prathamartz/unity-attributes","last_synced_at":"2026-02-02T00:02:24.711Z","repository":{"id":244164184,"uuid":"814443229","full_name":"PrathamArtz/Unity-Attributes","owner":"PrathamArtz","description":"Unity Attributes for Better Inspector Experience","archived":false,"fork":false,"pushed_at":"2024-06-13T06:41:32.000Z","size":14475,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T01:04:38.576Z","etag":null,"topics":["unity-attribute","unity-attributes","unity-attributes-for-better-inspector-experience","unity-editor","unity-inspector"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PrathamArtz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-13T03:08:14.000Z","updated_at":"2024-06-13T06:41:35.000Z","dependencies_parsed_at":"2024-06-13T07:32:31.611Z","dependency_job_id":"13087841-b04b-4b76-844e-90331bf903ea","html_url":"https://github.com/PrathamArtz/Unity-Attributes","commit_stats":null,"previous_names":["prathamartz/unity_attributes"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PrathamArtz/Unity-Attributes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrathamArtz%2FUnity-Attributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrathamArtz%2FUnity-Attributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrathamArtz%2FUnity-Attributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrathamArtz%2FUnity-Attributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PrathamArtz","download_url":"https://codeload.github.com/PrathamArtz/Unity-Attributes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrathamArtz%2FUnity-Attributes/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260269425,"owners_count":22983644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["unity-attribute","unity-attributes","unity-attributes-for-better-inspector-experience","unity-editor","unity-inspector"],"created_at":"2024-09-26T23:21:02.007Z","updated_at":"2026-02-02T00:02:24.683Z","avatar_url":"https://github.com/PrathamArtz.png","language":null,"readme":"# Unity_Attributes\nUnity Attributes for Better Inspector Experience\n\n1. [SerializeField](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#-serializefield)\n2. [HideInInspector](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#hideininspector)\n3. [Header](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#header)\n4. [Space](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#space)\n5. [Tooltip](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#tooltip)\n6. [Range](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#range)\n7. [TextArea](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#textarea)\n8. [HelpURL](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#helpurl)\n9. [RequireComponent](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#requirecomponent)\n10. [ContextMenuItem](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#contextmenuitem)\n11. [ContextMenu](https://github.com/PrathamArtz/Unity-Attributes?tab=readme-ov-file#contextmenu)\n\n\n\u003ch3\u003e Hello! Let's build on the following simple Unity script and improve the inspector experience for it by adding in attributes. \u003c/h3\u003e \n\n```\n\nusing UnityEngine;\n\npublic class ExampleScript : MonoBehaviour\n{\n    private float damageDealt = 5;\n    private int currentHealth = 50;\n    public int maxHealth = 100;\n    private string characterName = \"Unity\";\n    private string characterDescription = \"Unity Attributes\";\n}\n\n```\n\nIn the inspector view, it looks like this:\n\n![inspector view](https://github.com/PrathamArtz/Unity_Attributes/raw/main/Images/Inspector%20View.jfif)\n\nNote that only the public field maxHealth shows up on the inspector. All the private variables are hidden\n\n\u003cbr /\u003e\n\u003ch2\u003e SerializeField\u003c/h2\u003e \n\nTo expose private variables in the inspector so that you could change it, simply add the SerializeField attribute.\n\n\n```\n\nusing UnityEngine;\n\npublic class ExampleScript : MonoBehaviour\n{\n    [SerializeField] private float damageDealt = 5;\n    [SerializeField] private int currentHealth = 50;\n    public int maxHealth = 100;\n    [SerializeField] private string characterName = \"Unity\";\n    [SerializeField] private string characterDescription = \"Unity Attributes\";\n}\n\n```\n![SerializeField view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Images/SerializeField.jfif)\n\nInspector view with SerializeField addition\n\n\u003ch2\u003eHideInInspector\u003c/h2\u003e\nTo do the opposite and hide public variables from the inspector, simply add the HideInInspector attribute.\n\n\u003cbr\u003e\u003cbr /\u003e\n\n```\nusing UnityEngine;\n\npublic class ExampleScript : MonoBehaviour\n{\n    [SerializeField] private float damageDealt = 5;\n    [SerializeField] private int currentHealth = 50;\n    [HideInInspector] public int maxHealth = 100;\n    [SerializeField] private string characterName = \"Unity\";\n    [SerializeField] private string characterDescription = \"Unity Attributes\";\n}\n```\n![HideInInspector view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Images/HideInInspector.jfif)\n\nInspector view with HideInInspector addition\n\n\u003ch2\u003eHeader\u003c/h2\u003e\nNow, let's organize things a bit by adding in labels above the variables in the inspector by using the Header attribute.\n\n```\nusing UnityEngine;\n\npublic class ExampleScript : MonoBehaviour\n{\n    [Header(\"Character Stats\")]\n    [SerializeField] private float damageDealt = 5;\n    \n    [SerializeField] private int currentHealth = 50;\n    [HideInInspector] public int maxHealth = 100;\n\n    [Header(\"Character Description\")]\n    [SerializeField] private string characterName = \"Unity\";\n    [SerializeField] private string characterDescription = \"Unity Attributes\";\n}\n```\n![Header view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Images/Header.jfif)\n\nInspector view with Header addition\n\n\u003ch2\u003eSpace\u003c/h2\u003e\nTo further group variables in the inspector, let's also add in a space between the health and damage stats using the Space attribute.\n\n```\nusing UnityEngine;\n\npublic class ExampleScript : MonoBehaviour\n{\n    [Header(\"Character Stats\")]\n    [SerializeField] private float damageDealt = 5;\n\n    [Space(20)]\n\n    [SerializeField] private int currentHealth = 50;\n    [HideInInspector] public int maxHealth = 100;\n\n    [Header(\"Character Description\")]\n    [SerializeField] private string characterName = \"Unity\";\n    [SerializeField] private string characterDescription = \"Unity Attributes\";\n}\n```\n![Space view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Images/Space.jfif)\n\nInspector view with Space addition\n\n\u003ch2\u003eTooltip\u003c/h2\u003e\nVariable naming is difficult and sometimes variables just need more context. To help with this, we can use the Tooltip attribute so that when you hover over a variable in the inspector, more context about it shows.\n\n```\nusing UnityEngine;\n\npublic class ExampleScript : MonoBehaviour\n{\n    [Header(\"Character Stats\")]\n    [SerializeField] \n    [Tooltip(\"The damage dealt by the character\")]\n    private float damageDealt = 5;\n\n    [Space(20)]\n\n    [SerializeField] private int currentHealth = 50;\n    [HideInInspector] public int maxHealth = 100;\n\n    [Header(\"Character Description\")]\n    [SerializeField] private string characterName = \"Unity\";\n    [SerializeField] private string characterDescription = \"Unity Attributes\";\n}\n\n```\n![Tooltip view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Gif/Tooltip.gif)\n\nInspector Tooltip demo\n\n\u003ch2\u003eRange\u003c/h2\u003e\nAside from putting in raw numeric values in the inspector, we can also use the Range attribute to provide us a slider, which gives us more control over the input and prevent invalid values.\n\n```\nusing UnityEngine;\n\npublic class ExampleScript : MonoBehaviour\n{\n    [Header(\"Character Stats\")]\n    [SerializeField] \n    [Tooltip(\"The damage dealt by the character\")]\n    [Range(0f, 5f)]\n    private float damageDealt = 5;\n\n    [Space(20)]\n    \n    [SerializeField] private int currentHealth = 50;\n    [HideInInspector] public int maxHealth = 100;\n\n    [Header(\"Character Description\")]\n    [SerializeField] private string characterName = \"Unity\";\n    [SerializeField] private string characterDescription = \"Unity Attributes\";\n}\n```\n\n![Range view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Gif/Range.gif)\n\nInspector Tooltip demo\n\n\u003ch2\u003eTextArea\u003c/h2\u003e\nWith the string variables, we can do much better as well by providing a larger text area in the inspector, making it easier to edit and manage longer text content.\n\n```\nusing UnityEngine;\n\npublic class ExampleScript : MonoBehaviour\n{\n    [Header(\"Character Stats\")]\n    [SerializeField] \n    [Tooltip(\"The damage dealt by the character\")]\n    [Range(0f, 5f)]\n    private float damageDealt = 5;\n\n    [Space(20)]\n\n    [SerializeField] private int currentHealth = 50;\n    [HideInInspector] public int maxHealth = 100;\n\n    [Header(\"Character Description\")]\n    [SerializeField] private string characterName = \"Unity\";\n\n    [SerializeField] \n    [TextArea]\n    private string characterDescription= \"Unity Attributes\";\n}\n```\n![TextArea view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Gif/TextArea.gif)\n\nInspector TextArea view\n\n\u003ch2\u003eHelpURL\u003c/h2\u003e\nThis next attribute, the HelpURL, is useful in team projects. With it, you make it easier to access documentation through a link you provide.\n\n```\nusing UnityEngine;\n\n[HelpURL(\"https://www.renz.is/useful-unity-attributes-for-better-inspector-experience/\")]\npublic class ExampleScript : MonoBehaviour\n{\n    [Header(\"Character Stats\")]\n    [SerializeField] \n    [Tooltip(\"The damage dealt by the character\")]\n    [Range(0f, 5f)]\n    private float damageDealt = 5;\n\n    [Space(20)]\n\n    [SerializeField] private int currentHealth = 50;\n    [HideInInspector] public int maxHealth = 100;\n\n    [Header(\"Character Description\")]\n    [SerializeField] private string characterName = \"Unity\";\n\n    [SerializeField] \n    [TextArea]\n    private string characterDescription= \"Unity Attributes\";\n}\n```\n![HelpURL view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Images/HelpURL.jfif)\n\nClicking the question mark at the top right of the attached script component (outlined by a red box) will bring the user to the link you provided\n\n\u003ch2\u003eRequireComponent\u003c/h2\u003e\nNow, when a script is going to be using a specific component, the RequireComponent attribute is helpful in making sure that this specific component is assigned to the gameobject. Not only that, but it also won't allow the component to be removed from the object.\n\n```\nusing UnityEngine;\n\n[HelpURL(\"https://docs.unity.com/ScriptReference/Rigidbody.html\")]\n[RequireComponent(typeof(Rigidbody))]\npublic class ExampleScript : MonoBehaviour\n{\n    [Header(\"Character Stats\")]\n    [SerializeField] \n    [Tooltip(\"The damage dealt by the character\")]\n    [Range(0f, 5f)]\n    private float damageDealt = 5;\n\n    [Space(20)]\n\n    [SerializeField] private int currentHealth = 50;\n    [HideInInspector] public int maxHealth = 100;\n\n    [Header(\"Character Description\")]\n    [SerializeField] private string characterName = \"Unity\";\n\n    [SerializeField] \n    [TextArea]\n    private string characterDescription= \"Unity Attributes\";\n}\n```\n![RequireComponent view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Images/RequireComponent.jfif)\n\nRigidbody component has been attached automatically to the gameobject\n\n![RequireComponent view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Gif/RequireComponent.gif)\n\nRequireComponent attribute demo preventing the removal of the specified required component\n\n\u003ch2\u003eContextMenuItem\u003c/h2\u003e\n\nBy adding the ContextMenuItem attribute in a variable, you will be able to right click this variable in the inspector and run a function you specify.\n\n```\nusing UnityEngine;\n\n[HelpURL(\"https://docs.unity.com/ScriptReference/Rigidbody.html\")]\n[RequireComponent(typeof(Rigidbody))]\npublic class ExampleScript : MonoBehaviour\n{\n    [Header(\"Character Stats\")]\n    [SerializeField] \n    [Tooltip(\"The damage dealt by the character\")]\n    [Range(0f, 5f)]\n    private float damageDealt = 5;\n\n    [Space(20)]\n\n    [SerializeField] \n    [ContextMenuItem(\"Reset current health\", \"ResetCurrentHealth\")]\n    private int currentHealth = 50;\n\n    [HideInInspector] public int maxHealth = 100;\n\n    [Header(\"Character Description\")]\n    [SerializeField] private string characterName = \"Unity\";\n\n    [SerializeField] \n    [TextArea]\n    private string characterDescription= \"Unity Attributes\";\n\n    private void ResetCurrentHealth()\n    {\n        currentHealth = 100;\n    }\n}\n```\n![ContextMenuItem view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Gif/ContextMenuItem.gif)\n\nInspector ContextMenuItem demo\n\n\u003ch2\u003eContextMenu\u003c/h2\u003e\n\nTo conclude, the ContextMenu works the same way as the ContextMenuItem. It provides you access to run a function you again specify when you right click the script component in the inspector.\n\n```\nusing UnityEngine;\n\n[HelpURL(\"https://docs.unity.com/ScriptReference/Rigidbody.html\")]\n[RequireComponent(typeof(Rigidbody))]\npublic class ExampleScript : MonoBehaviour\n{\n    [Header(\"Character Stats\")]\n    [SerializeField] \n    [Tooltip(\"The damage dealt by the character\")]\n    [Range(0f, 5f)]\n    private float damageDealt = 5;\n\n    [Space(20)]\n\n    [SerializeField] \n    [ContextMenuItem(\"Reset current health\", \"ResetCurrentHealth\")]\n    private int currentHealth = 50;\n\n    [HideInInspector] public int maxHealth = 100;\n\n    [Header(\"Character Description\")]\n    [SerializeField] private string characterName = \"Unity\";\n\n    [SerializeField] \n    [TextArea]\n    private string characterDescription= \"Unity Attributes\";\n\n    private void ResetCurrentHealth()\n    {\n        currentHealth = 100;\n    }\n\n    [ContextMenu(\"Goodbye\")]\n    private void Goodbye()\n    {\n        Debug.Log(\"Goodbye now! Hope it helped.\");\n    }\n}\n```\n\n![ContextMenu view](https://github.com/PrathamArtz/Unity_Attributes/blob/main/Gif/ContextMenu.gif)\n\nContextMenu inspector demo\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprathamartz%2Funity-attributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprathamartz%2Funity-attributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprathamartz%2Funity-attributes/lists"}