{"id":3045,"date":"2021-01-02T13:48:13","date_gmt":"2021-01-02T05:48:13","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=3045"},"modified":"2021-01-02T19:44:41","modified_gmt":"2021-01-02T11:44:41","slug":"editing-class-properties-in-different-places-in-the-editor","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=3045","title":{"rendered":"Editing class properties in different places in the editor"},"content":{"rendered":"\n<p>When developing with Unreal, it is common for programmers to implement properties on Actors or other objects in C++, and make them visible in the editor for designer use. However, sometimes, it makes sense to view a property, or make it editable, but only on the object&#8217;s default state. Sometimes, the property should only be modifiable at runtime with the default specified in C++. Fortunately, there are some specifiers that can help us restrict when a property is available.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">How to do it&#8230;<\/h1>\n\n\n\n<ol><li>Create a new&nbsp;Actor&nbsp;class in the editor called&nbsp;PropertySpecifierActor:<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2021\/01\/1181d0a4-74a1-4ab3-ac08-773bf590a75a.png\" alt=\"\"\/><\/figure>\n\n\n\n<ol><li>Add the following property definitions to the class:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">#pragma once<br><br>#include \"CoreMinimal.h\"<br>#include \"GameFramework\/Actor.h\"<br>#include \"PropertySpecifierActor.generated.h\"<br><br>UCLASS()<br>class CHAPTER_09_API APropertySpecifierActor : public AActor<br>{<br>    GENERATED_BODY()<br>    <br>public: <br>    \/\/ Sets default values for this actor's properties<br>    APropertySpecifierActor();<br><br>protected:<br>    \/\/ Called when the game starts or when spawned<br>    virtual void BeginPlay() override;<br><br>public: <br>    \/\/ Called every frame<br>    virtual void Tick(float DeltaTime) override;<br><br>    \/\/ Property Specifiers<br>    UPROPERTY(EditDefaultsOnly)<br>    bool EditDefaultsOnly;<br><br>    UPROPERTY(EditInstanceOnly)<br>    bool EditInstanceOnly;<br><br>    UPROPERTY(EditAnywhere)<br>    bool EditAnywhere;<br><br>    UPROPERTY(VisibleDefaultsOnly)<br>    bool VisibleDefaultsOnly;<br><br>    UPROPERTY(VisibleInstanceOnly)<br>    bool VisibleInstanceOnly;<br><br>    UPROPERTY(VisibleAnywhere)<br>    bool VisibleAnywhere;<br>};<\/pre>\n\n\n\n<ol><li>Perform a&nbsp;Save,&nbsp;Compile&nbsp;your code, and launch the editor.<\/li><li>Create a new blueprint based on the class.<\/li><li>Open the blueprint and look at the&nbsp;Class Defaults&nbsp;section:<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2021\/01\/04d585d0-842c-4de5-b9da-731758e27c2b.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<ol><li>Note which properties are editable and visible under the&nbsp;Property Specifier Actor&nbsp;section:<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2021\/01\/1d639038-43e2-4ee8-abff-36f3ec2afa6b.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Location of the Property Specifier Actor<\/p>\n\n\n\n<ol><li>Place instances in the level and view their&nbsp;Details&nbsp;panels:<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/library\/view\/unreal-engine-4x\/9781789809503\/assets\/16d4fe8b-9f98-40b7-96de-36f7d1188c15.png\" alt=\"\"\/><\/figure>\n\n\n\n<ol><li>Note that a different set of properties is editable.<\/li><\/ol>\n\n\n\n<h1 class=\"wp-block-heading\">How it works&#8230;<\/h1>\n\n\n\n<p>When specifying&nbsp;UPROPERTY, we can indicate where we want that value to be available inside the Unreal editor.<\/p>\n\n\n\n<p>Visible*&nbsp;prefixes indicate that the value is viewable in the&nbsp;Details&nbsp;panel for the indicated object. The value won&#8217;t be editable, however.<\/p>\n\n\n\n<p>This doesn&#8217;t mean that the variable is a&nbsp;const&nbsp;qualifier; however, native code can change the value, for instance.<\/p>\n\n\n\n<p>Edit*&nbsp;prefixes indicate that the property can be altered within the&nbsp;Details&nbsp;panels inside the editor.<\/p>\n\n\n\n<p>InstanceOnly&nbsp;as a suffix indicates that the property will only be displayed in the&nbsp;Details&nbsp;panels for instances of your class that have been placed into the game. They won&#8217;t be visible in the&nbsp;Class Defaults&nbsp;section of the Blueprint editor, for example.<\/p>\n\n\n\n<p>DefaultsOnly&nbsp;is the inverse of&nbsp;InstanceOnly&nbsp;\u2013&nbsp;UPROPERTY&nbsp;will only display in the&nbsp;Class Defaults section, and can&#8217;t be viewed on individual instances within the level.<\/p>\n\n\n\n<p>The suffix\u00a0Anywhere\u00a0is the combination of the two previous suffixes\u00a0\u2013\u00a0the\u00a0UPROPERTY\u00a0will be visible in all the\u00a0Details\u00a0panels that inspect either the object&#8217;s defaults or a particular instance in the level.As we mentioned previously, if you are interested in learning more about Property Specifiers, check out the following link:\u00a0<a href=\"https:\/\/docs.unrealengine.com\/en-us\/Programming\/UnrealArchitecture\/Reference\/Properties\/Specifiers\">https:\/\/docs.unrealengine.com\/en-us\/Programming\/UnrealArchitecture\/Reference\/Properties\/Specifiers<\/a>. <\/p>\n\n\n\n<h1 class=\"wp-block-heading\">See also<\/h1>\n\n\n\n<ul><li>This recipe makes the property in question visible in the inspector, but doesn&#8217;t allow the property to be referenced in the actual Blueprint Event Graph. See the following recipe for a description of how to make that possible.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>When developing with Unreal, it is common for programme [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,1],"tags":[26],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3045"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3045"}],"version-history":[{"count":1,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3045\/revisions"}],"predecessor-version":[{"id":3063,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3045\/revisions\/3063"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}