Unreal Engine Livestream - Exposing C++ to Blueprints - Feb 7 - Live from HQ

WHAT
​​​​​Blueprint scripting is a great way to put power into the hands of your game designers. On this week’s livestream, Richard Hinckley will cover the different ways you can expose C++ code to Blueprints, expanding your game’s functionality.

WHEN
Thursday, Feb 7 @ 2:00PM ET - Countdown

WHERE
Twitch
Youtube
Facebook

WHO
Richard Hinckley - Senior Documentation Engineer
Amanda Bott - Community Manager - @amandambott](http://twitter.com/amandambott)
Victor Brodin - Community Manager - @victor1erp](http://twitter.com/victor1erp)

RELEVANT INFO
Documentation
Metadata Specifiers

COMMUNITY SPOTLIGHT

Himeko Sutori
https://store.steampowered.com/app/6…Himeko_Sutori/

Sky Shepherd

Tribute to Zaha Hadid 1000 museum
https://forums.unrealengine.com/comm…ojects/1577931

**ARCHIVE

**

very interesting … should be a good one!

I have a feeling this will be very useful for me as someone who has build their game 100% in blueprint and has always wanted to learn how to expose additional things.

Looking forward to it!

Thanks for the Livestream.
Is it possible to show how to expose c++ in actor,pawn,widget…and if there is a right way to expose variables globally .
Thanks.

This is great and something I always have trouble with. In my case I’m often trying to access weird functions that are there in c++ if only I could get them to work.

Examples for me have been:

Base64 encoding/decoding (String in / String out) - this is easily solvable now with plugins
Font kerning pairs (font and 2 characters in / float out) - couldn’t get this to work and frustrates me to this day
String to system’s copy/paste buffer - this is now available in rama’s plugin I think.

What i’m really bored with seeing in c++ tutorials is ‘here’s the player BP - lets make it do this when you press jump’ - i’d like to see more ways to expose functions to BPs and also to process things - for example take and array of something and process it with a for each to return new data etc.

Looking forward to this one…

Can you also talk about the issue with Blueprints and real-time multiplayer over mobile data connections… like the fact that we cant use blueprint nodes to connect to mobile subsystems (android or ios) unless we code the connections using c++ it would be great to know how to connect to the subsystems with a full blueprint project. There seems to be a lot of cases asking for a solution to this problem with blueprints and real-time multiplayer on mobile.

Cheers,

After watching the livestream “Exposing C++ to Blueprints” I’m writing down on this forum some outstanding questions. Question #2, #4, & #5 are my own however I am curious as to the answer to the others as I have encountered them myself though they were not my original questions and therefore I may have augmented their original intention by accident. I may end up private messaging an unreal member or post on the Discord channel. I’m including picture links that I was able to quickly get online for visual aid using UE4 tutorial videos/documentation.

Picture Reference
1 ) How to make** wildcard **parameters in C++. I know the select tool will be a wildcard until you attach one of the nodes. I also understand that from specific compiler perspective, the compiler requires variables to be defined so it may check the correctness of your code. This might be an exception like the pure/impure conversion of a casting node?

Picture Reference
2 ) How do you expose a blueprint to allow multiple variables to be connected to the same node? An example of this is the Hidden in Game node for components. I understand the workarounds which I’ve been using, but they seem unclean - a. I can make an array including each variable as an element of the array which be a tedious process when wanting to add 5+ specific items into a single array and having to continuously press the “+” button OR b. simply execute that function on each variable individually. Both the work arounds solve the issue, but I’d like, when possible, to make the code read cleaner.

Picture Reference
3 ) Passing delegates through functions particularly for binding purposes (perhaps as a variable). I’ve come across this myself when I wanted to pass a call upward particularly in a tree of actors. At the moment you have to know what you are listening for, make a function to bind another function then have the other function make a call to a known function. It ends up being tedious as well when you just want to pass a specific piece. On another note about delegates, you can only bind to one I believe. So if you want a few specific events to be bound to one event I believe you have to make a new binding for each to call the same function. There seems to be a couple things that could be done with delegates.

Picture Reference
4 ) I’ve tinkered with the Custom Gravity Plugin in a past project and noticed that it is possible to nest categories for variables using C++ but not in Blueprint. I’m curious as to how that happens. What I’m trying to describe is how you can assign a variable a “Category” and it helps organize the variables on the left panel. Well you can only have a single category. Turns out the Custom Gravity Plugin had a category within a category. So I could categorize a variable as “Gravity >> Movement” or “Gravity >> Navigation” or “Gravity >> Physics”.

Picture Reference
5 ) On the topic of organization I do use the ability to reorganize (usually exposed) variables in the blueprint panel from a blueprint perspective often. Any way to organize functions manually though? Is it possible to categorize them? At the moment functions are in one long list - especially when overriding. Perhaps I’m just ignorant of something which already exists I have seen nice improvement in splitting implemented functions into an “Interface” overarching category at least.

Picture Reference
6 ) There was a question during the livestream I’m just adding here for completeness. How do you create the conversion nodes? So if you want to make a conversion for a 2D vector to become 3D vector. During the livestream I believe the answer from chat was adding (somewhere) “autocast” to the C++.

Thanks again for the excellent stream.
SmashRash

  1. It is possible with ArrayParm meta specifier. Not sure how I’d do that for a single variable though. The way how I see it is that if I cannot force certain behaviour through options exposed to the macros, it is not worth it.

  2. I don’t think there is a function specifier for this. Digging through the source it seems that the target node is of type TArray itself, but I have no idea how I would implement that behaviour, at least it is not exposed to UFunctions. And even if it were to be implemented, I’d reckon it’d be closer to “automatically create an array of these variables” rather than “execute for each”.

  3. I can’t really say much about this because I can’t say I understand the situation all too well.

You can also make an event that calls the other events, and just bind that… ? But yeah, I can’t really picture the situation, so I don’t know what is going on.

  1. Creating sub-categories is possible I using the name of a category, then adding >> | << (just like in C++) and then writing the sub-category name.

  2. Details panel for the functions still has a category input, just like variables. Make sure the function is selected for the details panel to show up. Construction script doesn’t have that details panel, but self-created functions do.

  3. BlueprintPure, (function without execution pins) BlueprintAutoCast (metadata specifiers, automatically does Cast on return type).

Thanks for watching the stream! Sorry for the delay, it took a while to get this information together, and I also came up with some new things for a Part 2 stream, hopefully soon after GDC.

To start off, here are some useful documentation pages for this topic:
https://docs.unrealengine.com/en-US/…rence/Metadata
https://docs.unrealengine.com/en-US/…ons/Specifiers

On to the questions! I was able to get all of them except #2.

1: The StructBox plugin is a good example of this. Using the reference pages above, you can read up on the “CustomStructureParam” Meta tag and the “CustomThunk” Specifier. Those are the two pieces you need, along with the DECLARE_FUNCTION macro. For a really good example, look at the StructBox plugin that ships with the Engine. By default, this Plugin is disabled, but you can read the code, and you can enable the plugin to test it out in the BP graph editor.

2: Still working on this one! I’m not really sure what the rules are just yet.

3: Passing delegates is possible, but a little complicated. Here’s a simple example you can use:

At the top of our .h file:


// Declare our delegate types. Note that the function parameter and the variable are declared with different macros.
DECLARE_DYNAMIC_DELEGATE_OneParam(FMyTestDelegate, int32, TestIntParameter);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMyOtherTestDelegate, int32, TestIntParameter);


In our class (in the .h file):


// This function takes a delegate and can execute it as appropriate.
UFUNCTION(BlueprintCallable)
void DelegateTestFunction(const FMyTestDelegate& Callback);

// This will be visible in Blueprints, and we can pass it into DelegateTestFunction.
UPROPERTY(BlueprintAssignable)
FMyOtherTestDelegate OnSomeOtherEvent;

4 and 5: Both variables and functions have a “Category” dropdown in the BP editor. You can create multiple levels of hierarchy by typing into that dropdown with a value like “Category|Subcategory”. Once that’s done, you can drag other variables or functions into it, or set them with the dropdown. You can also do this in code with the “Category” Specifier in code, using the same syntax. Also in code, you can specify functions that explicitly list after other functions, or you can assign integer priority values to functions to affect their listing order. See the Metadata page linked above, and look for “DisplayPriority” and “DisplayAfter” for more information.

BONUS: Cast nodes changing from Pure to Impure with right-click came up in the stream. This is done in code and is fairly complex, using the UK2Node and UEdGraphNode interfaces. Check K2Node_DynamicCast.cpp and K2Node_DynamicCast.h for the actual “cast node” implementation, or look through those two parent interfaces for full details.

BONUS: To make a BP node with multiple output exec pins, make an enumerated type to provide the pin list. Give your function an output parameter of that enumerated type (by “output parameter” I just mean a reference to the enum type), and set the Meta tag ExpandEnumAsExecs to the name of that parameter in your UFUNCTION macro.

In the .h file:


UENUM()
enum class EMyOutputEnum : uint8
{
EPinZero,
EPinOne,
EPinTwo
};


Declaring the function in the class definition within the .h file:


UFUNCTION(BlueprintCallable, Meta = (ExpandEnumAsExecs = "OutputPinParameter"))
void MultipleOutputs(int32 InputParam, EMyOutputEnum& OutputPinParameter);

In the .cpp file:


void AMyActor::MultipleOutputs(int32 InputParam, EMyOutputEnum& OutputPinParameter)
{
// Just make sure you set this at some point before exiting.
OutputPinParameter = EMyOutputEnum::EPinOne;
}

Just out of interest, would you reply to this same topic if/when you find out the answer to #2 / other questions? I’d like to know which topic to keep an eye out for.

Super cool stream btw. I’m learning tons. ^^