x

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"

Accessing blueprint variables through C++

Hey, I've gotten fairly far in prototyping my game through blueprints. Now I've started rewriting some of the math heavy areas in custom C++ blueprint nodes. This is going well but I haven't been able to find a way to access variables made in blueprints through C++. Is there a way to get access to the blueprint created variables?

Also, is it a decent idea to make the heavier parts of the blueprints into C++ nodes? Rather than rewriting all blueprints in C++(I'm new to C++, so that's why I ask). Or will it not help much?

Thanks, sorry for the kind of confusing questions.

Product Version: Not Selected
Tags:
more ▼

asked Jan 21 '15 at 01:28 AM in C++ Programming

avatar image

Redsett
45 9 9 12

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

2 answers: sort voted first

You can access your blueprint variables from C++... but it's tedious. I would instead suggest that you move these variables to native instead. The you won't accidentally rename a variable that C++ code use.

It totally makes sense that you rewrite your calculation heavy stuff to C++, and just expose that functionality as nodes, so that you keep your overall logic in blueprint. It's really easy to do in C++. Also, it helps you keep your blueprints more clean, so it's more logic (where blueprints excel), and less math.

Cheers, Markus

more ▼

answered Jan 21 '15 at 07:53 AM

avatar image

MarkusRannare
156 6 9 17

avatar image Redsett Jan 21 '15 at 05:55 PM

Thanks a bunch Markus. How do I go about accessing the blueprint variables through C++ though? What is this tedious method you speak of. o.O

avatar image MarkusRannare Jan 22 '15 at 07:46 AM

This code snippet:

 static const FName MyProperty( TEXT("MyInt32Variable") );
 
 UClass* MyClass = GetClass();
 
 for( UProperty* Property = MyClass->PropertyLink; Property; Property = Property->PropertyLinkNext )
 {
     UIntProperty* IntProperty = Cast<UIntProperty>( Property );
     if( IntProperty && Property->GetFName() == MyProperty )
     {
         // Need more work for arrays
         int32 MyIntValue = IntProperty->GetPropertyValue( Property->ContainerPtrToValuePtr<int32>(this) );
         
         UE_LOG( LogSteve, Log, TEXT("Value is = %i"), MyIntValue );
         break;
     }
 }

will print a blueprint variable named "MyInt32Variable" that is of type Integer to the log in your class.

And it won't have any compile time checking, so if you change your type or name of the variable, it won't find it. So it's very sensitive to changes in the blueprint.

Cheers, Markus

avatar image Redsett Jan 23 '15 at 12:59 AM

Sweet, I assume this is to be used inside of the blueprint c++ file with the variable. How would I find the blueprint with the variable from a different c++ file?

Sorry for the newb questions, it took me a couple hours of experimenting to find out that much. :D

avatar image Redsett Jan 23 '15 at 01:04 AM

I'm trying to make a BP node with this inside of it. The function not being static causes some weirdness also. But it gives errors with it being static.

.h

 UFUNCTION(BlueprintPure, meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject", FriendlyName = "My Print Var", CompactNodeTitle = "PrntVar", Keywords = "My Print Var"), Category = Custom)
     void MyPrintVar(int32 &ints);

.cpp

void UMyEdGraphNode::MyPrintVar(int32 ∫s) { static const FName MyProperty(TEXT("MyTestInt"));

 UClass* MyClass = GetClass();

 for (UProperty* Property = MyClass->PropertyLink; Property; Property = Property->PropertyLinkNext)
 {
     UIntProperty* IntProperty = Cast<UIntProperty>(Property);
     if (IntProperty && Property->GetFName() == MyProperty)
     {
         // Need more work for arrays
         ints = int32(IntProperty->GetPropertyValue(Property->ContainerPtrToValuePtr<int32>(this)));

     }
     else
     {
         ints = 2;
     }
 }

}

avatar image MarkusRannare Jan 23 '15 at 07:41 AM

I would not suggest going this route! It's very error prone, and I just showed it as a prof of concept. Only use it in EXTREME situations when you know EXACTLY what you are doing. Going down this path will just be a pain when doing it too much.

I would suggest watching Spazchicken tutorials. And then instead of making a node that changes your Blueprint variables, make a native function that does some fancy heavy operation and returns a value that is then assigned to your blueprint variable. That way you will have much clearer vision in the blueprint and can see how the flow happens.

avatar image Redsett Jan 23 '15 at 05:36 PM

Thanks for the suggestion Markus, I'll take it. And thanks for helping out!

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

you might want to check out https://www.youtube.com/watch?v=ubVpYz_x_Ig it's a tutorial about creating a blueprint for a weapon and creating variables from C++ to the blueprint for real time use. I'm creating classes and them plugging them to a blueprint for easy orientation of the objects ect. I then make the action/gameplay stuff via C++

more ▼

answered Jan 23 '15 at 01:23 AM

avatar image

spazchicken
447 35 20 53

avatar image Redsett Jan 23 '15 at 02:08 AM

Hey Spazchicken, I'm actually trying to go the other way. Getting/Editing a variable from blueprints in C++.

Either way I'll watch your tutorial, no doubt I'll learn something. Thanks!

avatar image spazchicken Jan 23 '15 at 02:15 AM

like what?

avatar image Redsett Jan 23 '15 at 02:46 AM

Making a variable in blueprints and then editing it in C++.

avatar image spazchicken Jan 23 '15 at 02:47 AM

ohh you mean through the visual scripting , I don't know about that, sorry :(

(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