Does anyone have an idea how this would work?
I’ve been searching and trying stuff but I feel I haven’t come close to a solution.
Just for some perspective:
I am making a tool that hooks on to UE from “outside”, lets say an interface for controlling parts of the editor.
What I need to do is the following -
get a list of all the defined events (or atleast the custom ones)
call them
Basically what I want is an external button for calling a event so that lets say a light turns on.
I have the communication part, I have the event part, now i need to somehow create a list of existing events in the project and trigger them
For starters, how to get these items in the “EventGraph” part, I need the exact same list but in C++
I only know one way to call functions in blueprint from c++, you can use BlueprintImplementableEvent function. It let you can call functions in blueprint from c++. If you use this, you should create a blueprint class inherit from your class with the BlueprintImplementableEvent function, and overwrite it in blueprint.
After that, you may most of your following logic in blueprint (such as invoke the event list).
All information about the class (this include blueprints) is in reflection system. Reflection system keep information about code stracture so it can be refrenced, you probably already aware of UClass which are part of reflection system. reflection system keep information in objects for each kind of code element created when C++ module or blueprint asset is loaded and they all based from UField class:
Events on back end are just cosmetically different functions, so in reflection system they be represented by UFunction objects. Use TFieldIterator to loop thru UFunctions from UClass of blueprint
On each loop check if UFunction has FUNC_BlueprintEvent flag with this function
If it has it add them in array to make a list of them
Note that blueprint need to be compile for reflection system to be updated and event to be visible to the rest of UE4, anything in non-compiled blueprint is invalid anyway.
Also note that this way you can get any information about classes native and blueprints ,thats what reflection system was made for and this is how UE4 see all properties and functions to begin with. It also nice way to create self generating UI in the game.
Thank you very much for that, I think it’s extremely helpful and pushing me in the right direction!
I managed to get stuff, but I don’t seem to be getting the stuff I thought I would
For instance I have this loop through all actors, and if its the blueprint one, log out all functions available. I don’t really see the events in the blueprint that I made, nor the “EventTick” or “Event Play”
Maybe I am misunderstanding this?
for (TActorIterator<AActor> ActorInstance(()); ActorInstance; ++ActorInstance)
{
UE_LOG(LogTemp, Warning, TEXT("Actor found - %s"), *ActorInstance->GetName());
for(TFieldIterator<UFunction> func(ActorInstance->StaticClass()); func; ++func) {
if (ActorInstance->GetName() == "SpotLight_Blueprint_5")
{
UE_LOG(LogTemp, Warning, TEXT("Function found - %s"), *func->GetName());
}
}
}
and the output is (without the actor list, just the spotlight blueprint actor):
LogTemp: Warning: Actor found - SpotLight_Blueprint_5
LogTemp: Warning: Function found - WasRecentlyRendered
LogTemp: Warning: Function found - UserConstructionScript
LogTemp: Warning: Function found - TearOff
LogTemp: Warning: Function found - K2_GetComponentsByClass
… needed to shorten for posting…
LogTemp: Warning: Function found - GetActorEnableCollision
LogTemp: Warning: Function found - GetActorBounds
LogTemp: Warning: Function found - ForceNetUpdate
LogTemp: Warning: Function found - FlushNetDormancy
LogTemp: Warning: Function found - EnableInput
LogTemp: Warning: Function found - DisableInput
LogTemp: Warning: Function found - DetachRootComponentFromParent
LogTemp: Warning: Function found - AddTickPrerequisiteComponent
LogTemp: Warning: Function found - AddTickPrerequisiteActor
LogTemp: Warning: Function found - AddComponent
LogTemp: Warning: Function found - ActorHasTag
LogTemp: Warning: Function found - ExecuteUbergraph
How would I retrieve TurnRed, TurnGreen events for instance?
I havent managed to post the comment here (as a comment to you), looks to me like a bug in commenting, but i added my response as a comment to the thread
For future reference and lost people
I have managed to invoke the thing, not quite sure what the frame/buffer is for but managed to get it to invoke so for now it will do without knowing it in depth, simplified example
No problem, i think reflection system is one of unused things around here, it let you do great stuff ^^
Also for future remember to post comment instead of answer if it’s not answer ;]
Yes I am aware of that, but to put it further in context, I am creating a plugin, so the events aren’t my own, they are user events that someone has created in their project, so I cannot edit or control them, they are already there to begin with and I need to get a list so I can fire them