Access variable from C++ class from blueprint

In my player’s class is a public variable called score. Now I want to increase the amount of this variable by using a blueprint. How do I do that?

Hi Karwler,

You should declare variable like this

UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
int32 Score;

And set you variable like here

Hope it helps!

That is not exactly what I ment. The thing is that I have two different classes (Coin and Ball) and I have one blueprint which inherits everything from the Coin class. Now I want to access a variable which is in the ball class from my blueprint.

Hi Karwler,

You should think about blueprint like a class in C++. When you drag-and-drop blueprint to the scene, It creates instance (equals to the class instantiation in C++). You should get variable reference, and retrieve variable from this object.

In first example, I add variable (NewVar – reff to BallBp blueprint) and setup this variable in editor for CoinBp instance.

In second example, I iterate over all BallBp actors and get variable.

Summary: to get variable from another blueprint, you should have instance of this blueprint (does not matter in which way you get it).

Best regards,

Ok then. Now I have one question left: How would I do the same thing in C++?

In C++ you cannot get property declared in Blueprint.

However, you can do next thing:

Declare reference to another class

UPROPERTY(EditAnywhere, Category=Options)
ABall* BallActor;

To get variable:

If (BallActor)
	BallActor->Score = 5;

You should setup reference to ABall actor in editor.

Actually, it is not only one-way to get link to another actor. You can ‘link’ actors during spawning, searching it, etc.

Hope it helps!

Hi ,

Not sure but isn’t it possible to get Blueprint variables in C++ using FindField?