How i create a c++ value and use in blueprint?

i want to declare a value in C++,and then use this value in blueprint,just like:

class XXX_API AXXX : public ACharacter

UPROPERTY(EditAnywhere, Category = "Demo")
USceneComponent* Source;

void doSomethingOnSource();

then some blueprint extends from AXXX,but each subclass’s Source is different,and i want to set Souce value,but i can’t not set compoent which i add in blueprint.

B inherit from AXXX,B is blueprint,and i add a springArm in B blueprint,i want to set this springArm to Source,but i can not edit it in B blueprint Editor,Source need set in B Scene,and i can not set B’s springArm to Source.

To read & write a UPROPERTY, I think it’s mandatory to use the specifier BlueprintReadWrite.
But I’m really not sure this is a good process, unless you can’t do in an another fashion.

I would say it’s better to create and add components in c++ if you need the reference there. Because it’s really easy to expose c++ to BP, but not so in the other route.

Anyway, if you use UPROPERTY(BlueprintReadWrite), you’ll be able to set the variable as long as it inherites from the correct class.

Thanks for silik1 reply,but i want to know how to set a instance to a property,for example,i make a character base class with a USceneComponent* in c++,then i make a bp form that class,and how i set this USceneComponent* for a camera i add on bp?

**Setting C++ Component Pointers in Blueprint Constructor Script**

Hi there!

This should get you what you want, which is the ability to link a C++ pointer of a component to a component created in the BP of the C++ base class.

I recommend setting the pointer in your BP constructor script.


USceneComponent* JoyfulCamera;


BP Constructor Script (in Editor)

Then in BP constructor script for your C++ base class, Set the JoyfulCamera pointer to the BP Camera component.

You might want to use the actual camera component ptr instead in case you wish to access member variables of the camera in C++


UCameraComponent* JoyfulCamera;


Any Component Will Work

This code concept of only declaring the pointer in C++ will work for ANY component that you wish to create in BP instead.

UStaticMesh* JoyfulMesh;


I use this model frequently because setting all the default parameters for a component is a lot more fun to do in BP than in C++ constructor, and as long as you set the variable in your constructor script of your BP it is quite a secure method.




Jaï Jaï Rama! :slight_smile: