What are the property specifiers?

Property specifiers are way to add additional info into variable or function you are creating. There are lots of different specifiers are we are going through all of them here. What these property specifiers can do then? First of all, they are your way to communicate between the C++ and the Blueprints. You can for example make some specific variable or function to be visible or callable inside the Blueprint or set that some specific data is shown inside the details panel. Specifiers are also used if you want some variable to be replicated (replication is used in online gaming). Basically, Property specifiers are crucial part of the programming when using the C++.

Official documentation about Specifier can be found Here

How to use the Property specifiers?

Using the specifiers is very straight forward. When creating a function or variable, you just type UPROPERTY() or UFUNCTION() on top of the variable/function.

 

Property1In this case. We have an actor. We give it one variable, type of int32 and a function that returns nothing. We set UPROPERTY to be VisibleAnywhere and BlueprintReadWrite and UFUNCTION to be Blueprincallable. If we later create a Blueprint version of this class. We can call the SomeFunction() inside Blueprint and we could see and set the value of someValue variable.

 
 
 

 

 

Specifiers

AdvancedDisplay


If AdvancedDisplay specifier is set. Variable only shows under Advanced settings in Details panel.


Let's take a look normal case first. In this case we have set UPROPERTY to be VisibleAnywhere and set Category to "Actor". This means, when we look Actor Tab in details panel, we can see our variable in there (Some Value).

UPROPERTY(VisibleAnywhere, Category="Actor")
int32 SomeValue;

SomeValueShowing


If we use UPROPERTY AdvancedDiaplay. We need to press the arrow that says "Show Advanced" before we can see our variable.

UPROPERTY(VisibleAnywhere, AdvancedDispay Category="Actor")

SomeValueShowing
 
There is nothing more to say about AdvancedDisplay UPROPERTY. It is pretty straightforward


AssetRegistrySearchable


The AssetRegistrySearchable keyword indicates that this property and its value will be automatically added to the asset registry for any asset class instances containing this as a member variable. It is not legal to use on struct properties or parameters. To see this Specifier in action, please check the Asset Registry tutorial


BlueprintAssignable


BlueprintAssignable is a specifier that is used with the Delegates. Delegates are a larger subject and we will not go through them here. To see full details about Delegates go to Delegates Page.

Now, let's focus on the matter in hand! In this tutorial, we have a three class to toy with. First, We have our GameMode class called APortFolioPrjGameMode, then we have an class called C_EmptyActor and finally we have a blueprint class based on the C_EmptyActor class, we call that a BP_EmptyActor. Now, what does the BlueprintAssignable specifier actually do? It allows us to call the Delegates we create in C++, inside a blueprint. Let's check how it works.

Because we are using the Delegates, we first need to add one. Delegates are added just before the UCLASS() macro. Our Delegate will have one parameter. Delegate name is FMyTestDelegate. Parameter is a type of FString and we name it as MyString. Name comes to play when we are using delegates in Blueprint. Coder/Artist can instantly come to conclusion what the parameter does by looking it's name.

So Inside our APortFolioPrjGameMode class header:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMyTestDelegate, FString, MyString);
UCLASS(minimalapi)

After that we will create our Delegate. We use the UPROPERTY(BlueprintAssignable) so we can call use this in Blueprint. We set it in Private so other classes cannot access it.

private:
UPROPERTY(BlueprintAssignable)
FMyTestDelegate MyTestingDelegate;

After that. We create a function that will broadcast the delegate. As you know, Functions are public. We name our Function as BroadCastDelegate();. You can pick any name of course!

public:
UFUNCTION()
void BroadCastDelegate();

In .CPP file we going to create declaration for our Function. Remember that we set one parameter that is a type of FString. So we need to add some FString along with the broadcasting. Our Function will do nothing more than a broadcast our newly created Delegate to listeners.

void AMyGameMode::BroadCastDelegate()
{
	MyTestingDelegate.Broadcast("MyTestText");
}

That is all we need to do with GameMode. We did nothing more than added a Function that will broadcast a Delegate called MyTestingDelegate and set UPROPERTY to be BlueprintAssignable. Now let's continue. Our C_EmptyActor class is actually an empty! So all we have to edit is a BP_EmptyActor. To create a Blueprint from C++ class you need to right click your mouse when cursor is over the C++ class and select the "Create blueprint class Based on ... ".

So in our Blueprint class we are going to get reference to our game mode and Vola! Our C++ created Delegate is there!Fine

All that is left to do, is to call the Function BroadCastDelegate(); inside our GameMode. In this particular case, i created a keybinding inside our Player Character that will call the BroadCastDelegate()-Function in GameMode class. Of course it is up to you to figure out, when and how you want to broadcast the delegate.

APortFolioPrjGameMode* CurGameMode = Cast(UGameplayStatics::GetGameMode(GetWorld()));
PlayerInputComponent->BindAction("BroadcastDelegate", IE_Pressed, CurGameMode, &APortFolioPrjGameMode::BroadCastDelegate);

In end result. When player presses key assigned to BroadcastDelegate, GameState will broadcast to all listeners. In this case, we print "MyTestText"
Printing


BlueprintCallable


There are two BlueprintCallables. One is for the UFUNCTION and one is for the UPROPERTY, just so you ain't mix them accidentally. UPROPERTY(BlueprintCallable) is very similar to UPROPERTY(BlueprintAssignable). They are both used with Delegates, but only difference is, that BlueprintAssignable is for assigning the Delegate and BlueprintCallable is for calling the Delegate. So, we start exactly the same. You can use any Actor class to try this. We start by creating our delegate just above the UCLASS. This time, we are going to create Delegate with two parameters. First Delegate name, then parameter type and parameter name.

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FMyBlueprintCallableDelegate, FString, MyString, int32, SomeValue);
UCLASS()

After that, we are going to create a variable from it and use the BlueprintCallable specifier.

//Delegates
UPROPERTY(BlueprintCallable)
FMyBlueprintCallableDelegate MyUsableDelegate;

That is all we need to do. If we create a blueprint class based on the C++ class, We can now call the Delegate in blueprints:
a1


BlueprintReadOnly


BlueprintReadOnly is very straightforward. This specifier allows the variable only to be GET in blueprint, but it cannot be SET in there. This does not affect the variable visibility in Class Defaults or Details panel. Only in Blueprint Graph Editor.

protected:
UPROPERTY(BlueprintReadOnly)
bool MyTestingBool;

a1


BlueprintReadWrite


BlueprintReadWrite similar to BlueprintReadOnly, but you can now also SET the Variable in Blueprint Graph.

protected:
UPROPERTY(BlueprintReadWrite)
bool MyTestingBool;

a1


Category


Specifies the category of the property. nested categories can be defined using the | operator.

protected:
UPROPERTY(BlueprintReadOnly, Category="Bools|TestingBool")
bool MyTestingBool;

a1


Config


Config Specifier allows a Variable to be instantly inserted into a Config file or to be loaded from there without writing a single line of code. Config files are larger subject and you can see full tutorial about the configs in here. But basicaly, Config files are fully editable by user. It can allow user to override specific values if they for example want a huge drawing distance or just want to mess with some game values for lulz. Many AAA RPG-titles have a config files, Skyrim and Watch Dogs are good examples.

But for now, let's do a quick Run-through of how this specifier works! First, when we create an class we need to set the Class Specifier. Again, Class Specifier are huge subject we go through in Class Specifiers section. By giving a Class Specifier "config = MySettings", we are giving this class right to write into a config file. In this particular case, we are creating our own INI file called MySettings. Config needs it's own include "ConfigCacheIni.h", so remember to add that also.


#include "ConfigCacheIni.h"
UCLASS(config = MySettings)

After this, if you open your game and compile it, you will have a MySettings.ini file in folder "SavedConfigWindows" folder. There are lot of other configuration files there also. After that. Let's go back to our editor and add two variables.

UPROPERTY(Config, BlueprintReadOnly)
FName PlayerName;

UPROPERTY(Config, BlueprintReadOnly)
int32 Sensitivity;

Open your .INI file and add these lines. First line is YourProjectName.ClassName

[/script/PortFolioPrj.C_EmptyActor] 
Sensitivity=250
PlayerName = Chloe 

Now, when we open our game, all the values are loaded into variables that have a specifier called Config (and have a same variable name)! Remember, Config files are only loaded when the project is started. So you cannot edit the Config files at Runtime and expect results.


DuplicateTransient


Indicates that the variable's value should be reset to the class default value during any type of duplication (copy/paste, binary duplication, etc.).

So if we have a Editable variable inside our class and it has a DuplicateTransient property, the variable will always reset as our default value when we create duplication from it. In this case it would turn into "Default"

UPROPERTY(EditInstanceOnly, DuplicateTransient)
FString MyTestString = "Default";

In this picture we created duplicate from left ball by alt-dragging. Left ball had MyTestString variable as "Something Different". After alt-dragging the MyStestString is "Default".
a1


EditAnywhere


If Variable has a property "EditAnywhere", it can be changed in our Class Defaults Tab and in Defaults tab inside Instance of that class. Class Defaults can be found when you open the class for editing. Instance tab can be found when you place the actor in level and then left click it with mouse.

UPROPERTY(EditAnywhere, DuplicateTransient)
FString EditAnywhereText = "Default";

a1


EditDefaultsOnly


Similar to EditAnywhere property, but you can only change variable when editing the class, not in instance of the class.


EditFixedSize


Only useful for dynamic arrays. This will prevent the user from changing the length of an array via the Unreal Editor property window.

In Class header we are creating the array

UPROPERTY(EditFixedSize, EditAnywhere)
TArray MyAwesomeArray; 

In CPP, we set some values inside that array

int32 tableinit[] = { 4, 8, 15, 16, 23, 42 };
MyAwesomeArray.Append(tableinit, ARRAY_COUNT(tableinit));

In Blueprint, we can change and edit the values, but we cannot add more array elements.
a1


EditInstanceOnly


Similar to EditAnywhere property, but you can only change variable when editing the instance of a class, not in full class editor.


GlobalConfig


Works just like Config except that you cannot override it in a subclass. Cannot be given a value in default properties. Implies ReadOnly.


Instanced


When instanced property is used, you can get reference to another object and change it's values in Details tab.

UPROPERTY(Instanced, EditAnywhere)
AC_EmptyActor* ReferencedActor;

In our editor, we see additional slot for editing the values. Note that you need to get reference to your object somehow. Pippet tool is hidden when using the Instanced so what i usually do is use the Construction Script.
a1

a1


Interp


Variables that use Interp specifier can be driven over time by a track in Matinee / Level Sequencer.

UPROPERTY(Interp)
FVector SomeVector;

a1


NoClear


Prevents this object reference from being set to none from the editor. Hides clear (and browse) button in the editor.

UPROPERTY(NoClear, BlueprintReadWrite, EditAnywhere)
AActor* CantHideMe;

a1


NonTransActional


Indicates that changes to this variable value will not be included in the editor's undo/redo history.


Replicated


I'm hidden!


ReplicatedUsing


I'm hidden!


RepRetry


I'm hidden!


SaveGame


I'm hidden!


SimpleDisplay


I'm hidden!


Transient


I'm hidden!


VisibleAnywhere


I'm hidden!


VisibleDefaultsOnly


I'm hidden![/bg_collapseO


VisibleInstanceOnly


I'm hidden!