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"

Store a reference to a BP event in C++ and call it

Hi there!

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

Product Version: UE 4.21
more ▼

asked Dec 05 '18 at 11:51 PM in C++ Programming

avatar image

39 3 5 11

avatar image CraftyWeazel Dec 05 '18 at 11:57 PM

Here is a drawing of what I intend to do. Hope this helps. alt text

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

I managed to do it this way:

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 ^^

more ▼

answered Dec 13 '18 at 11:23 PM

avatar image

39 3 5 11

avatar image Evigmae Dec 13 '18 at 11:36 PM

hey there, glad you could get it done... but why do you need to do this for? =O

avatar image CraftyWeazel Dec 13 '18 at 11:54 PM

Ahah, yeah that's a bit weird I must admit ^^

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 ^^

avatar image Evigmae Dec 14 '18 at 01:35 AM

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.

alt text

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.

dialoguesystem.jpg (44.9 kB)
avatar image CraftyWeazel Dec 14 '18 at 07:31 AM

Oh, really nice!

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

Here you can have a pick at what I've done (and maybe help me a little further :P) : https://answers.unrealengine.com/questions/857656/view.html All the overkill I've been doing is for the user sanity!

avatar image Evigmae Dec 14 '18 at 11:16 AM

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.

avatar image CraftyWeazel Dec 16 '18 at 01:18 PM

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.


(comments are locked)
10|2000 characters needed characters left

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.

alt text

Which would let you create an Event in blueprints callable from C++.

alt text

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)

set.png (4.3 kB)
bp.png (31.8 kB)
more ▼

answered Dec 06 '18 at 03:14 AM

avatar image

1.4k 6 3 7

avatar image CraftyWeazel Dec 06 '18 at 02:41 PM

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.

(comments are locked)
10|2000 characters needed characters left
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