Download

Blueprint Runtime Introspection, Calling and Modification from C++

Hello All,

I am attempting to implement the following system of functions, although the outline I’ve given is pretty rough.
The format of the table below is [calling language] → [function name and arguments]


Blueprint --> LuaCreateContext() //calls C++11 function of the same name below
Blueprint --> LuaLoadLibrary(Context, "libname") //^^^

Blueprint --> LuaAddBPFunction(Context, Function, "funcname") //^^^
Blueprint --> LuaRemoveBPFunction(Context, Function) //^^^
Blueprint --> LuaRemoveBPFunction(Context, "funcname") //^^^

Blueprint --> LuaCallFunction(Context, "funcname", ArgList) //^^^

C++11 --> LuaCreateContext() //I have this covered
C++11 --> LuaDestroyContext(Context) //^^^
C++11 --> LuaLoadLibrary(Context, "libname") //^^^

C++11 --> LuaAddBPFunction(Context, Object, Function, "funcname")
C++11 --> LuaRemoveBPFunction(Context, Object, Function)
C++11 --> LuaRemoveBPFunction(Context, Object, "funcname")

C++11 --> LuaCallFunction(Context, "funcname", ArgList) //have this covered
C++11 --> LuaAddFunction(Context, Function, "funcname") //may have to make workaround

LuaJIT --> (seamlessly call functions added by C++ and Blueprints)

I can work around whatever restrictions exist between C++11 and Blueprints, but I first need to know how Blueprints can be manipulated from C++.

From C++11, can I get a list of the Blueprint functions (including non-C++11) available to a given object?
From C++11, can I get the name, return type and argument types of a non-C++11 Blueprint function?
From C++11, can I call an existing non-C++11 Blueprint function?

And, on a related note (but more out of curiosity than necessity)…
Can I make a C++11 function available to a Blueprint at runtime, especially without inheritance?

I’ve looked at “Exposing Gameplay Elements to Blueprints”, and while I could get away with a warped version of the API under that model, I’d like to know if maybe there’s more I can do.

It sounds like you’re looking to reflect function information from the Unreal Property System.

An example of finding all of the blueprint-callable functions implemented by a UClass might look something like this (untested):



for( TFieldIterator<UFunction> Iter(GetSomeUClass(), EFieldIteratorFlags::IncludeSuper, EFieldIteratorFlags::ExcludeDeprecated); Iter; ++Iter )
{
    UFunction* Func = *Iter;
    if ( Func->HasAnyFunctionFlags(FUNC_BlueprintCallable) )
    {
        // This function is exposed to Blueprint...
    }
}


And at a glance it looks like you can get some info about the return type like this:


FString FuncReturnType = Func->GetReturnProperty() ? Func->GetReturnProperty()->GetCPPType() : FString("void");

Since you’re working on a lua integration, have you looked at the source code for the example scripting integration plugin? https://forums.unrealengine.com/showthread.php?3958-Scripting-Language-extensions-via-plugins

Have you seen this thread: https://forums.unrealengine.com/showthread.php?3958-Scripting-Language-extensions-via-plugins ?

Scripting plugins may contains some of the things you’re looking for.

Thanks for the advice!
Holy goodness, that is a powerful plugin.
I don’t need a full reflection of the entire Unreal Property System, I just need to be able to quickly and easily cherrypick some BP functions at runtime and expose them to a Lua environment. The goal is for this Lua environment to be exposed to the player, so it should probably not have such deep access to UE4.
I’ll go ahead and investigate. Thanks again!