Today I created an ActorComponent. Everything looks great until I tried to make a Blueprint component class derived from it. The editor didn’t allow me to save changes I made to the properties in the class like a normal bp class would.
Check the sample code below:
UCLASS() class USampleComponent : public UObject{ GENERATED_BODY() public: UPROPERTY() float TestProperty; //This will not be saved if you have a bp class --> USampleComponent. //Some other members ... };
This doesn’t work due to the definition of the property. We need to specify two things:
1. The UCLASS needs to be a BlueprintType.
2. The property needs to be BlueprintReadWrite—which enables bp to read and write the value, and EditAnywhere—which allows users to change the value through detail panel or archetype bp editor.
Let’s check the result:
UCLASS(BlueprintType)//1 class USampleComponent : public UObject{ GENERATED_BODY() public: UPROPERTY(EditAnywhere, BlueprintReadWrite)//2 float TestProperty; //Some other members ... };
Then we can go back to our bp class, and the value can be saved and loaded by Unreal Engine even for the derived class.
There are many specifiers for defining the proper behaviors of UPROPERTYs. If you would like to know more, please check this link below.