Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: Not Selected
more ▼

asked Jan 15 '15 at 12:14 PM in Blueprint Scripting

avatar image

138 10 11 26

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hi Karwler,

You should declare variable like this

 UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
 int32 Score;

And set you variable like here

alt text

Hope it helps!

setscore.png (38.3 kB)
more ▼

answered Jan 15 '15 at 12:48 PM

avatar image

1.8k 76 19 143

avatar image Karwler Jan 15 '15 at 04:31 PM

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.

avatar image Gleb.Bulgakov Jan 16 '15 at 10:54 AM

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. img 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, Gleb

getvariable.png (308.2 kB)
avatar image Karwler Jan 16 '15 at 03:41 PM

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

avatar image Gleb.Bulgakov Jan 19 '15 at 04:52 PM

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!

avatar image ryanjon2040 Jan 19 '15 at 05:06 PM

Hi Gleb,

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question