{"id":294,"date":"2019-04-29T06:55:43","date_gmt":"2019-04-29T06:55:43","guid":{"rendered":"https:\/\/docs.sisus.co\/power-inspector\/?p=294"},"modified":"2021-03-24T17:29:38","modified_gmt":"2021-03-24T17:29:38","slug":"class-member-visibility","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/power-inspector\/getting-started\/class-member-visibility\/","title":{"rendered":"03. Class Member Visibility"},"content":{"rendered":"<h1><strong>Member Visibility in Power Inspector<\/strong><\/h1>\n<p>By default Power Inspector displays <strong><a href=\"https:\/\/docs.sisus.co\/power-inspector\/terminology\/members\/\">class members<\/a><\/strong> similarly to the <strong><a href=\"https:\/\/docs.sisus.co\/power-inspector\/terminology\/default-inspector\/\">default inspector<\/a><\/strong> for consistency and intuitiveness.<br \/>\nHowever, it gives you the ability to expose practically any class members when you want to.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-202\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/2019\/04\/DisplayAnything.png\" alt=\"\" width=\"594\" height=\"255\" srcset=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/DisplayAnything.png 594w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/DisplayAnything-300x129.png 300w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/DisplayAnything-150x64.png 150w\" sizes=\"(max-width: 594px) 100vw, 594px\" \/><\/p>\n<blockquote><p><strong>Tip<\/strong>: You can <strong>customize<\/strong> what <a href=\"https:\/\/docs.sisus.co\/power-inspector\/preferences\/show-non-serialized-fields\/\">fields<\/a>, <a href=\"https:\/\/docs.sisus.co\/power-inspector\/preferences\/show-properties\/\">properties<\/a> and <a href=\"https:\/\/docs.sisus.co\/power-inspector\/preferences\/show-methods\/\">methods<\/a> are shown in Power Inspector <strong>by default<\/strong> via the <strong><a href=\"https:\/\/docs.sisus.co\/power-inspector\/preferences\/01-preferences-list\/\">preferences<\/a><\/strong>.<\/p><\/blockquote>\n<h1><strong>Member Visibility in the Default Inspector<\/strong><\/h1>\n<p>The default inspector only displays class members when they pass <strong>all<\/strong> of the following conditions:<\/p>\n<ol>\n<li>It is a <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/programming-guide\/classes-and-structs\/fields\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>field<\/strong><\/a>.<\/li>\n<li>It is <strong>not <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/keywords\/static\">static<\/a><\/strong>.<\/li>\n<li>It does <strong>not<\/strong> have the <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/keywords\/const\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>const<\/strong> keyword<\/a>.<\/li>\n<li>It does <strong>not<\/strong> have the <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/keywords\/readonly\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>readonly<\/strong> keyword<\/a>.<\/li>\n<li>It is <strong>not<\/strong> <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/programming-guide\/generics\/generic-classes\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>generic type<\/strong><\/a>.<\/li>\n<li>It is <strong>not<\/strong> <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/keywords\/abstract\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>abstract type<\/strong><\/a>.<\/li>\n<li>Its type is <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/keywords\/built-in-types-table\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>primitive<\/strong><\/a>, <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/keywords\/enum\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>enum<\/strong><\/a>, <strong>Unity built-in type<\/strong>\u00a0or <strong><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/keywords\/struct\" target=\"_blank\" rel=\"noopener noreferrer\">struct<\/a><\/strong> or <strong><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/programming-guide\/classes-and-structs\/classes\" target=\"_blank\" rel=\"noopener noreferrer\">class<\/a><\/strong> with the <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.serializableattribute?view=netframework-4.8\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Serializable<\/strong> attribute<\/a>.<\/li>\n<li>It is <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/keywords\/public\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>public<\/strong><\/a>, or has the <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/SerializeField.html\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>SerializeField<\/strong> <strong>attribute<\/strong><\/a>.<\/li>\n<li>(It does <strong>not<\/strong> have the <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/HideInInspector.html\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>HideInInspector<\/strong> <strong>attribute<\/strong><\/a><strong>.<\/strong>)<\/li>\n<\/ol>\n<p>These strict limitations leave out a lot of valid use cases, where it would be useful to see data in the <a href=\"https:\/\/docs.sisus.co\/power-inspector\/terminology\/inspector\/\">Inspector<\/a> but it&#8217;s <strong>not possible<\/strong> (at least without going through the trouble of writing <a href=\"https:\/\/docs.unity3d.com\/Manual\/editor-CustomEditors.html\" target=\"_blank\" rel=\"noopener noreferrer\">Custom Editors<\/a>). Say you would like to expose a Dictionary field in the inspector, and handle its serialization manually; this is not possible in the default inspector but can easily be done with Power Inspector.<\/p>\n<h1><strong>Attributes For Controlling Member Visibility<\/strong><b><\/b><\/h1>\n<h2><strong>ShowInInspector<\/strong><\/h2>\n<p>Power Inspector introduces a new <strong><a href=\"https:\/\/docs.unity3d.com\/Manual\/Attributes.html\" target=\"_blank\" rel=\"noopener noreferrer\">attribute<\/a><\/strong> for customizing member visibility: <strong>ShowInInspector<\/strong>.<br \/>\nWhen added before any <strong>field, property, indexer<\/strong> or <strong>method, <\/strong>the class member will become visible inside the <a href=\"https:\/\/docs.sisus.co\/power-inspector\/terminology\/inspector-view\/\">inspector<\/a>.<br \/>\nAnother benefit of using this attribute is that it tells the compiler that the class member in question can be assigned implicitly. What this does it gets rid of misleading warning messages like &#8220;Field &#8216;X&#8217; is never assigned.&#8221; or &#8220;Method &#8216;X&#8217; is never used.&#8221; &#8211; as they actually can be assigned and used via the Inspector!<\/p>\n<h3><strong>Usage<\/strong><\/h3>\n<ol>\n<li>Add \u201c<strong>using Sisus.Attributes;<\/strong>\u201d at the beginning of your script file.<\/li>\n<li>Add \u201c<strong>[ShowInInspector]<\/strong>\u201d before the definitions of class members that you want to show up in the inspector.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/ShowButtonInInspector.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" class=\"alignnone wp-image-307 size-full\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/ShowButtonInInspector.png\" alt=\"\" width=\"831\" height=\"239\" srcset=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/ShowButtonInInspector.png 831w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/ShowButtonInInspector-300x86.png 300w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/ShowButtonInInspector-768x221.png 768w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/ShowButtonInInspector-150x43.png 150w\" sizes=\"(max-width: 831px) 100vw, 831px\" \/><\/a><\/p>\n<blockquote><p><strong>Tip: <\/strong>If you have another attribute named exactly \u201cShowInInspector\u201d, you can also use that to tag class members, and they will still be shown in Power Inspector.<\/p><\/blockquote>\n<h2><strong>SerializeField<\/strong><\/h2>\n<p>Unity has the <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/SerializeField.html\"><strong>SerializeField<\/strong><\/a> attribute, which can be added to non-public fields in order to tell Unity to serialize them and show them in the inspector.<\/p>\n<p>Power Inspector will display any fields that have this attribute (<strong>note<\/strong>: fields will be visible in Power Inspector even if Unity can&#8217;t actually serialize the field).<\/p>\n<p><strong>Usage<\/strong><\/p>\n<ol>\n<li>Add \u201c<strong>using UnityEngine;<\/strong>\u201d at the beginning of your script file.<\/li>\n<li>Add \u201c<strong>[SerializeField]<\/strong>\u201d before the definitions of fields that you want to show up in the inspector.<\/li>\n<\/ol>\n<h2><strong>SerializeField with Properties<\/strong><\/h2>\n<p>C# has a feature that makes it possible to have an attribute target the field of an auto-implemented property. Using this feature, it is possible to both <strong>serialize and expose<\/strong> <strong>properties<\/strong> in the inspector.<\/p>\n<p>Power Inspector will automatically display the property backing field with label generated from the name of the property.<\/p>\n<p><a href=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialized-property-backing-field.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" class=\"alignnone wp-image-1747 size-full\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialized-property-backing-field.png\" alt=\"\" width=\"1035\" height=\"205\" srcset=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialized-property-backing-field.png 1035w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialized-property-backing-field-300x59.png 300w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialized-property-backing-field-1024x203.png 1024w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialized-property-backing-field-768x152.png 768w\" sizes=\"(max-width: 1035px) 100vw, 1035px\" \/><\/a><\/p>\n<p><strong>Usage<\/strong><\/p>\n<ol>\n<li>Add \u201c<strong>using UnityEngine;<\/strong>\u201d at the beginning of your script file.<\/li>\n<li>Add \u201c<strong>[field: SerializeField]<\/strong>\u201d before the definitions of auto-properties that you want to show up in the inspector.<\/li>\n<\/ol>\n<h2>Serialize Reference<\/h2>\n<p>For serializing more complex data types such as abstract types, generic types and classes containing cyclical references Unity offers the <strong><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/SerializeReference.html\">SerializeReference<\/a><\/strong> attribute.<\/p>\n<p>Power Inspector will display any fields that have this attribute (<strong>note<\/strong>: fields will be visible in Power Inspector even if Unity can&#8217;t actually serialize the field).<\/p>\n<p>For abstract types Power Inspector will allow you to assign an instance of any implementing type through a convenient popup menu.<\/p>\n<div id=\"attachment_1752\" style=\"width: 859px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialize-reference-example.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img aria-describedby=\"caption-attachment-1752\" loading=\"lazy\" class=\"wp-image-1752 size-full\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialize-reference-example-thumbnail.png\" alt=\"\" width=\"849\" height=\"229\" srcset=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialize-reference-example-thumbnail.png 849w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialize-reference-example-thumbnail-300x81.png 300w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/04\/serialize-reference-example-thumbnail-768x207.png 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><p id=\"caption-attachment-1752\" class=\"wp-caption-text\">click to see full code<\/p><\/div>\n<p><strong>Usage<\/strong><\/p>\n<ol>\n<li>Add \u201c<strong>using UnityEngine;<\/strong>\u201d at the beginning of your script file.<\/li>\n<li>Add \u201c<strong>[SerializeReference]<\/strong>\u201d before the definitions of fields that you want to show up in the inspector.<\/li>\n<\/ol>\n<h2><strong>EditorBrowsable<\/strong><\/h2>\n<p>The <strong><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.componentmodel.editorbrowsableattribute?view=netframework-4.8\" target=\"_blank\" rel=\"noopener noreferrer\">EditorBrowsable attribute<\/a><\/strong> is a <strong>built-in alternative<\/strong> to the ShowInInspector attribute.<br \/>\nAny field, property, indexer or method that contains this attribute (initialized with the default constructor) will be shown in Power Inspector.<br \/>\nNote that this attribute does <strong>not<\/strong> automatically tell the compiler that the class member in question can be assigned implicitly. However, you can still do this manually by also adding the <strong><a href=\"https:\/\/www.jetbrains.com\/help\/resharper\/Reference__Code_Annotation_Attributes.html#UsedImplicitlyAttribute\" target=\"_blank\" rel=\"noopener noreferrer\">UsedImplicitly attribute<\/a><\/strong> before the class member.<\/p>\n<blockquote><p><strong>Why EditorBrowsable?<\/strong> You might choose to use this instead of the ShowInInspector attribute if you want to avoid coupling your code with references to attributes that don&#8217;t come built-in with Unity. This can be convenient if you ever need to use the same code in a project that doesn&#8217;t include Power Inspector.<\/p><\/blockquote>\n<h3><strong>Usage<\/strong><\/h3>\n<ol>\n<li>Add the line \u201c<strong>using System.ComponentModel;<\/strong>\u201d at the beginning of your script file.<\/li>\n<li>Add the line \u201c<strong>[EditorBrowsable]<\/strong>\u201d before the definitions of class members that you want to show up in the Inspector View.<\/li>\n<\/ol>\n<h2><strong>ContextMenu<\/strong><\/h2>\n<p>If the <strong><a href=\"https:\/\/docs.sisus.co\/power-inspector\/preferences\/show-methods\/\">Show Methods preference item<\/a><\/strong> has been configured to <strong>ContextMenu<\/strong>, then all methods with the <strong><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/ContextMenu.html\" target=\"_blank\" rel=\"noopener noreferrer\">ContextMenu attribute<\/a><\/strong> will show up as buttons in the Inspector View.<br \/>\nHowever, by default this behaviour has been disabled in Power Inspector.<\/p>\n<h3><strong>Usage<\/strong><\/h3>\n<ol>\n<li>Make sure you have the line \u201c<strong>using UnityEngine;<\/strong>\u201d at the beginning of your script file.<\/li>\n<li>Add the line \u201c<strong>[ContextMenu(&#8220;<span class=\"sig-kw\">ItemName&#8221;<\/span>)]<\/strong>\u201d before the methods that you want to show up in the Inspector View.<\/li>\n<\/ol>\n<h2><strong>HideInInspector<\/strong><\/h2>\n<p>Class members with the <strong><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/HideInInspector.html\">HideInInspector attribute<\/a><\/strong> will not be shown in Power Inspector (unless <strong><a href=\"https:\/\/docs.sisus.co\/power-inspector\/features\/debug-mode\/\">Debug Mode+<\/a><\/strong> is enabled).<\/p>\n<h3><strong>Usage<\/strong><\/h3>\n<ol>\n<li>Make sure you have the line \u201c<strong>using UnityEngine;<\/strong>\u201d at the beginning of your script file.<\/li>\n<li>Add the line \u201c<strong>[HideInInspector]<\/strong>\u201d before the definitions of class members that you want to hide in the Inspector View.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Member Visibility in Power Inspector By default Power Inspector displays class members similarly to the default inspector for consistency and intuitiveness. However, it gives you the ability to expose practically any class members when you want to. Tip: You can customize what fields, properties and methods are shown in Power Inspector by default via the ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/power-inspector\/getting-started\/class-member-visibility\/\" title=\"read more\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/294"}],"collection":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/comments?post=294"}],"version-history":[{"count":45,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/294\/revisions"}],"predecessor-version":[{"id":1793,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/294\/revisions\/1793"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/media?parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/categories?post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/tags?post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}