I would like advice from programmers on UE4 about this question: from a custom blueprint node that expands in a UK2Node_CallFunction, how can I send to a C++ function the reference of an event created in blueprints?
Then, with that reference, what is the good way to fire it when necessary, from anywhere?
If you have the same answers for BP Functions instead of BP Events, I’m also interested.
Leads I’m on:
Generate an event with CompilerContext.SpawnIntermediateEventNode and try to store its FMemberReference, which led to error messages.
Bind the event in blueprints with a Delegate pin (the little red square), but I’m absolutely clueless on how to do this…
Thank you in advance, I really need your help there…
I’m wondering if you’re looking at this the wrong way.
If you want to have a BP event callable from C++, you would just create a function in C++ and mark it BlueprintImplementableEvent. Which means it doesn’t have to have an implementation on C++ as it will be implemented in Blueprints.
You could add BlueprintCallable in there and call it from Blueprints as well.
Which would let you create an Event in blueprints callable from C++.
it could have any parameters you like too.
Calling blueprint functions from C++ doesn’t make much sense though. that’s not how you should try to use those. You often wanna create C++ functions and call them from Blueprints though.
BlueprintImplementableEvent is meant to allow designers to add some front-end stuff when C++ needs it. C++ is great with hardcore logic, Bp is great with dynamic asset references (eg, effects, sounds, materials, etc)
Hi Evigmae, thank you for your answer.
Actually, I think what you said is a really good advice for anyone, and usually I follow this way of doing as it is consistant with Unreal team advices (C++ backend for programmers, BP frontend for designers).
However, my specific case really needs me to get a BP-event reference into a C++ function. The reason why is because this event isn’t made by the user but rather generated during blueprint compilation (with CompilerContext.SpawnIntermediateEventNode()). The idea is to create a new entry point in the event graph with a “pure” node (no input exec, but one output exec). When compiling, the “pure” node is replaced by a generated Custom Event node and a C++ function that stores this new event’s reference. Then, it can fire it anytime.
1 - My node :
It’s a “pure” node that I managed not to get purged during the first phases of blueprint compilation - somehow - and which leads to an exec wire. The idea : it’s creating an UObject that can be stored in a variable of the blueprint, and then some functions can be called on it later. One of the function must call the nodes that are connected to the “pure” node by the exec wire, like an event would do. Somehow, it’s like a “stored event”, but it also stores a lot of other things and requires some inputs, which an event couldn’t do.
2 - Expansion :
At BP-compilation time, the node create an intermediary Custom Event with a custom name so that’s it is unique. This event only exists during compilation and is later forgotten, when all blueprint-script is translated to executable code by kismet compiler.
The node also replaces itself with a call to a function in a blueprint function library I made. One of the arguments of this function is a FName : the name of the event that was just created.
3 - The function :
Later on, when that function is executed by the object owning the node, a simple custom delegate I registered is bound to the event with its FName and with the reference to the calling object.
At last, when another function is called, that same delegate is used to fire the event in the source object, now that it is bound.
The important thing to consider is that it’s not possible to bind the delegate at compile time, or do anything that would refer to the newly created event, because it’s not compiled nor registered yet. I had to store its name somewhere and wait for the end of the compilation to finally bind it.
I also did the same with newly created properties in the source object, for the same project with veeeryyy specific needs ^^
It’s for a dialog system I’m developping. I want it to be fully made inside the blueprint editor, however blueprints aren’t made for this kind of application at all.
My nodes - dialog nodes - generate an object of type “Dialog”, which basically contains a chain of references to “DialogEvent” objects. Most of these objects only contains static texts and behaviors, but some of them need to trigger blueprint events at runtime, like assigning a new value to a variable, or triggering an event in the environment.
It is also necessary to read some of the source blueprint’s variables dynamically during runtime. For example, a NPC could tell “I have 5 chicken in my yard!”, which would be wrong if the player killed 2 of them before. Therefore I need my dialog node to dynamically read the “Chicken” variable in the character’s blueprint and place it inside the text.
There are other ways to do it, like I saw in the great Dialogue System plugin by CodeSpartan, but it’s way too complicated to setup for designers imo. I wanted to give it a UX-design polish ^^
oh boy, That’s so cool. Isn’t it a bit overkill though? xP
I did a dialogue system a couple of years ago for a game, it was all done in blueprint. it did much of what you mention. designers would handle it from the actors themselves, and had to input some “code” i designed to operate it, guess these days i could make something a lot fancier and simpler to handle.
I had like 6 months experience with unreal and didn’t even knew C++ back then.
it allowed for dialogue trees, and was a fully dynamic and customizable system, you could make it read data off the game too.
Personally i don’t like having designers peeking inside the game, i like to give them high-level front-end tools to play with. Though my old dialogue system would often break when designers used the code wrong, lol.
Yeah, I know they are thousand ways to build a proper dialogue system (why is everybody writing dialogue and not dialog? Is it an American/English subtelty?). Either with Excel tables, or editor arrays - what you seem to have chosen at your time -, or even a new editor graph like CodeSpartan’s plugin.
But all of these ways disappointed me somehow, mostly because it wasn’t user-friendly, and I thought we could make a better thing, more flexible and easy to use. The “blueprint-ready” component was really important, because you would design all your dialog branching in a graph editor and directly merge it with blueprint code (either dynamic-reading of properties, or dynamic-firing of events).
Would love to help! but what you’re doing is a bit too advanced for me to be honest.
Also google says “dialogue” means conversation, and “dialog” means a window on a computer screen.
I created a topic now that I can show something to people
Don’t hesitate to give your feedback, especially if you’ve been working on something similar before.