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"

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

Product Version: UE 4.20
Tags:
more ▼

asked Jul 21 '18 at 11:46 PM in C++ Programming

avatar image

LifeArtist
47 8 13 18

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

1 answer: sort voted first

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.

http://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/UField/ http://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/UFunction/index.html

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)

https://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/FindField/2/index.html

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

http://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/TFieldIterator/index.html

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

http://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/UObject/ProcessEvent/index.html

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

more ▼

answered Jul 22 '18 at 01:34 AM

avatar image

Shadowriver
36.7k 932 169 1111

avatar image LifeArtist Jul 22 '18 at 11:45 AM

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.

avatar image Shadowriver Jul 23 '18 at 09:17 AM

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:

http://api.unrealengine.com/INT/API/Runtime/Engine/Engine/UBlueprint/GetBlueprintClass/index.html

From there you get UClass :) Remeber that UClass of blueprint already exist in memory and you can get it in constructor using TClassFinder for example https://answers.unrealengine.com/questions/451693/what-is-the-right-syntax-of-fclassfinder-and-how-c.html 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

https://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/TObjectIterator/index.html

avatar image LifeArtist Jul 23 '18 at 08:25 PM

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: alt text

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. ;)

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.

avatar image Shadowriver Jul 23 '18 at 11:41 PM

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

avatar image LifeArtist Jul 24 '18 at 12:34 AM

Brilliant, thanks! Works like a charm.

alt text

(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