Examine Blueprint's functions with Python/CPP?

Are there any possibilities to display all functions declared in one blueprint through the experimental python plugin? Furthermore getting the function calls from a specific function? I was experimenting with that and couldn’t really figured it out.
I managed to get a list of all Assets but what do I have to do next?

I guess somehow I need to build that blueprint class to access its declared functions !?

If it does not work with python is there any why to achieve that with a c++ plugin?

Regards,

LifeArtist

I can tell you where that information is and how to do in C++

UE4 has reflection system which tracks infomation about code structure, each element is represented by UField object that is created when engine is initiated and your module is loaded (in case of blueprint when asset system is loaded, you cam’t get it then load the blueprint asset) and each element type has own class, you probably already know one called UClass for clases as it most commonly used UField class.

Note that UFields is created both C++ and Blueprint classes and in case of C++ only thigns maked with macros (UPROPERTY, UFUNCTION etc) are visible in reflection system, otherwise those things cna be only used in C++ (most notably struct functions which reflection system don’t support at all but you can still use them in C++)

UClass is easy to get (UStruct is also easy with StaticStruct()), to get UFunction to UProperty that is part of UClass you need to use TFieldIterator or FindField function

T will be UField class you searching so in your case UFunction, Owner is the class field is in (UClass inherence from UStruct so dont worry) and String name is a name of function (try adding spaces if it does not work)

here example of TFieldIterator:

for (TFieldIterator<UFunction> It(Class); It; ++It)
{
	UFunction* Function = *It;
        //Do things
}

This will loop across all functions ofcorse, all of them inherent and C++ and blueprint, or else you set 2nd argument of iterator to ExcludeSuper

If you choose to get all of them you can check, you can check if function if blueprint by checking if Native flag is not set and get and check owning class with GetOuterUClass() function to filter them out.

To call function from UFunction can use ProcessEvent function on object you want to call on

Params need to be any struct with types of arguments of function declared in exact same or order, void* will accept any pointer, but it gonna read the data as that struct with those types of arguments.

Now as for Python… i don’t know :pi never codef in Python and i yet to touch it in UE4, one thing for sure if it using only exposed things same as blueprint then doing this is impossible in blueprints, but again i yet to even touch Python in UE4 so maybe some other person will have anwser for that

Thanks for your explaination! However I have implemented the TFieldIterator loop but the only function I have seen is ExecuteUbergraph. What I want is to see all function names and function calls from a Custom Event / Function.

LogTemp: Warning: Found Assets: 1
LogTemp: Warning: Asset Name: Blueprint /Test/MyActor.MyActor
LogTemp: Warning: Function Name: ExecuteUbergraph

My Code looks like this:

AssetRegistryModule.Get().GetAssetsByPath("/Test", AssetData);

UE_LOG(LogTemp, Warning, TEXT("Found Assets: %d"), AssetData.Num())
for (FAssetData data : AssetData)
{
	UE_LOG(LogTemp, Warning, TEXT("Asset Name: %s"), *data.GetFullName())
	for (TFieldIterator<UFunction> It(data.GetClass()); It; ++It)
	{
		UFunction* Function = *It;
		UE_LOG(LogTemp, Warning, TEXT("Function Name: %s"), *Function->GetName());
	}
}

Somehow I expected to get all functions from the Blueprint with this code.

Thats because AssetData give only UBlueprint which is asset object of blueprint, so you only see exposed function of UBlueprint class. To get blueprint UClass you need to use this function on UBlueprint:

From there you get UClass :slight_smile: Remeber that UClass of blueprint already exist in memory and you can get it in constructor using TClassFinder for example What is the right syntax of FClassFinder and how could I generaly use it to find a specific blueprint? - Blueprint - Epic Developer Community Forums
You can also loop thru UClasses using TObjectIterator<UClass>, but it’s quite expensive process, you should do that only once to create array of UClasses you want

unfortunately, even with this modification I am only able to get the ExecuteUbergraph.

UE_LOG(LogTemp, Warning, TEXT("Asset Name: %s"), *data.GetFullName())
UObject* uobject = data.GetAsset();
if (IsValid(uobject))
{
	UE_LOG(LogTemp, Warning, TEXT("valid uobject"))
}
else
{
	UE_LOG(LogTemp, Warning, TEXT("not valid uobject"))
}
UE_LOG(LogTemp, Warning, TEXT("Object Name: %s"), *uobject->GetName())
UBlueprint* bclass = Cast<UBlueprint>(uobject);
if (IsValid(bclass))
{
	UE_LOG(LogTemp, Warning, TEXT("valid"))
}
else
{
	UE_LOG(LogTemp, Warning, TEXT("not valid"))
}
for (TFieldIterator<UFunction> It(bclass->GetBlueprintClass()); It; ++It)
{
	UFunction* Function = *It;
	UE_LOG(LogTemp, Warning, TEXT("Function Name: %s"), *Function->GetName());
}

This is my modified code. My Blueprint looks like this:

248249-unreal-functions.png

Another function GetAllGraphs instead was giving me all the graphs:

LogTemp: Warning: Graph Name: UserConstructionScript
LogTemp: Warning: Graph Name: SimpleFunction
LogTemp: Warning: Graph Name: EventGraph

Which is kind of what I wanted. So know I would iterate over all the nodes of all graphs. But I am still interesting in your solution because this looks better.

As you probably questioning your self why do I want to do this. I want to get all function from an actor and all functions which are getting called within that actor. To produce a sequence diagram of called functions for the specific actors. :wink:

EDIT:
Btw do you know how can I use UK2Node_FunctionEntry I really dont know what to import. If I import the .h file which is mentioned within the docs ( Editor/BlueprintGraph/Classes/K2Node_FunctionEntry.h ) its only working for VS intellisense but not when compiling in UE.

Sorry forgot, try GeneratedClass it a varable in UBlueprint :pAlso you should use UFunction because K2Nodes only exist in asset in editor and won’t be on runtime

Brilliant, thanks! Works like a charm.

248298-unreal-get-functions.png