{"id":3062,"date":"2021-01-02T13:49:41","date_gmt":"2021-01-02T05:49:41","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=3062"},"modified":"2021-01-02T19:44:31","modified_gmt":"2021-01-02T11:44:31","slug":"making-properties-accessible-in-the-blueprint-editor-graph","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=3062","title":{"rendered":"Making properties accessible in the Blueprint editor graph"},"content":{"rendered":"\n<p>The specifiers we mentioned in the previous recipe are all well and good, but they only control the visibility of\u00a0UPROPERTY\u00a0in the\u00a0Details\u00a0panel. By default, even with those specifiers used appropriately,\u00a0UPROPERTY\u00a0won&#8217;t be viewable or accessible in the actual editor graph for use at\u00a0runtime.Other\u00a0specifiers, which can optionally be used in conjunction with the ones in the previous recipe so that you can interact with properties in the Event Graph.<\/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 called&nbsp;BlueprintPropertyActor&nbsp;using the editor wizard:<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2021\/01\/40067092-2b56-401c-8825-8bfea89f5019.png\" alt=\"\"\/><\/figure>\n\n\n\n<ol><li>Add the following&nbsp;UPROPERTY&nbsp;to the class using Visual Studio:<\/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 \"BlueprintPropertyActor.generated.h\"<br><br>UCLASS()<br>class CHAPTER_09_API ABlueprintPropertyActor : public AActor<br>{<br>    GENERATED_BODY()<br>    <br>public: <br>    \/\/ Sets default values for this actor's properties<br>    ABlueprintPropertyActor();<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><strong>    UPROPERTY(BlueprintReadWrite, Category = Cookbook)<\/strong><br><strong>    bool ReadWriteProperty;<\/strong><br><br><strong>    UPROPERTY(BlueprintReadOnly, Category = Cookbook)<\/strong><br><strong>    bool ReadOnlyProperty;<\/strong><br><br>};<\/pre>\n\n\n\n<ol><li>Perform a&nbsp;Save,&nbsp;Compile&nbsp;your project, and start the editor.<\/li><li>Create a Blueprint class based on your&nbsp;BlueprintPropertyActor&nbsp;and open its graph.<\/li><li>From the&nbsp;My Blueprint&nbsp;panel, click on the eye icon to the right of the&nbsp;Search&nbsp;bar. From there, select&nbsp;Show Inherited Variables:<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2021\/01\/04be7b53-3abc-4b96-91df-41feeef6a5b6.png\" alt=\"\"\/><\/figure>\n\n\n\n<ol><li>Verify that the properties are visible under the&nbsp;Cookbook&nbsp;category&nbsp;in the&nbsp;Variables&nbsp;section of the&nbsp;My Blueprint&nbsp;panel:<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2021\/01\/bba20056-25a1-4ae7-90cf-639c18d06265.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<ol><li>Left-click and drag the&nbsp;ReadWriteProperty&nbsp;variable into the&nbsp;Event Graph. Then select&nbsp;Get ReadWriteProperty:<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2021\/01\/5ba2bbaf-baa3-48ca-ab9c-c7c14d66d450.png\" alt=\"\"\/><\/figure>\n\n\n\n<ol><li>Repeat the previous step, but instead select&nbsp;Set ReadWriteProperty.<\/li><li>Drag the&nbsp;ReadOnly&nbsp;property into the graph and note that the&nbsp;SET&nbsp;node is disabled:<\/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\/b43adb75-6bdf-41e5-b6ec-2d103fb65f05.png\" alt=\"\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">How it works&#8230;<\/h1>\n\n\n\n<p>BlueprintReadWrite&nbsp;as a&nbsp;UPROPERTY&nbsp;specifier indicates to the Unreal Header Tool that the property should have both&nbsp;Get&nbsp;and&nbsp;Set&nbsp;operations exposed for use in Blueprints.<\/p>\n\n\n\n<p>BlueprintReadOnly&nbsp;is, as the name implies, a specifier that only allows Blueprint to retrieve the value of the property; never set it.<\/p>\n\n\n\n<p>BlueprintReadOnly&nbsp;can be useful when a property is set by native code, but should be accessible within Blueprint.<\/p>\n\n\n\n<p>It should be noted that\u00a0BlueprintReadWrite\u00a0and\u00a0BlueprintReadOnly\u00a0don&#8217;t specify anything about the property being accessible in the\u00a0Details\u00a0panels or the\u00a0My Blueprint\u00a0section of the editor:\u00a0these specifiers only control the generation of the getter\/setter nodes for use in Blueprint graphs.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The specifiers we mentioned in the previous recipe are  [&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\/3062"}],"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=3062"}],"version-history":[{"count":2,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3062\/revisions"}],"predecessor-version":[{"id":3350,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3062\/revisions\/3350"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}