Connect C++ to Blueprints

Hello,

Firstly apologies if this has been asked 100s of times, I’ve looked and can’t find anything :frowning:

I have a C++ class and I can add UFUNCTIONS and get them to show in the BP editor.

What I can’t find is any info on how to pass data to and from the C++ object instance and the bp?

I want to pass in a reference/pointer to a sound asset but how to do this generically for whatever type is what I’m after.

Thanks :slight_smile:

If I understand your problem, you need the UPROPERTY macro with BlueprintReadWrite specified. Your member var should also be declared as protected to be accessed from BP.

Here a link of all specifiers: https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Properties/Specifiers/

Thanks for that, that helps a lot :slight_smile:

I have another q…

if I want to say provide my own custom print string function

e.g.:

UFUNCTION(BlueprintCallable, Category = “test BP Library”)
void printInfo(const std::str message);

I get the following error:

Error: Cannot find class ‘’, to resolve delegate ‘str’

I was hoping the BP user could provide the actual message in the bp node?

UE4 doesn’t use the STL library. If you change your method to the following, it would work:




UFUNCTION(BlueprintCallable, Category = "Test BP Library")
void printInfo(const FString& Message); // If the Compiler complains about passing a const reference, then just drop it to pass by value.


ahh ok, thanks for that!

Changing to an FString builds with no errors or warnings :slight_smile:

Are all the types that can be used as BP params F<type>'s?

can you pass native int’s, float doubles etc?

F just is the identifier for a struct. Normal value types (int, float, etc) are fine although Blueprints don’t accept certain types (unsigned anything, long, long long, double, etc).

See:
Introduction to C++ Programming in UE4 | Unreal Engine Documentation for an overview of the various common types in UE4.