I created a custom UK2Node that (1) makes requests to a remote server, and (2) asynchronously fires outputs as soon as we have a response from the server.
The node was implemented by extending UK2Node_BaseAsyncTask. Here’s how it looks like:
In this case, I use the input exec pin to make the server request. Everything works beautifully!
I would like to make my node to work without input exec pins**. **
That is, my server requests would be done under the hood as soon as the game starts (e.g. BeginPlay). Like an input key node, no input pins would be displayed. Outputs would stay as they are (i.e. fired whenever we have a response from the server). Something like this:
Would you have any idea on how I could implement this?
PS: I spent some time studying the classes UK2Node_InputKey & UK2Node_InputKeyEvent, but I’m still not sure how they transfer to my case. Maybe I’m missing some background info on how they work?
BaseAsyncTask is a callable node.
You would have to use a different base class and do some trickery in ExpandNode() to spawn to the compiler context the delegates, just like BaseAsyncTask already does for you.
Obrigado, [USER=“434”]BrUnO XaVIeR[/USER]! Thanks a lot for your help!
Would you have suggestions of potential base classes I might want to take a look at?
I tried to study both UK2Node_InputKey & UK2Node_InputTouch. While they don’t seem to be good base classes, they seem to do what I’m looking for. Each of them use complementary K2Node_*Event class (e.g. K2Node_InputKey & K2Node_InputKeyEvent) to get the job done. However, the logic starts to get abstract and confusing to me (e.g. K2Node_InputKeyEvent uses InputKeyDelegateBinding that uses an array of BlueprintInputKeyDelegateBindings…) so that I can’t extract much useful knowledge. Maybe someone could give me a hand here?
I would create a node based on UK2Node_CustomEvent and bind a delegate there…
Then within its ExpandNode() function I will spawn the actual node above, but just as a simple UK2Node_CallFunction.
On visual graph I would make it look something like this:
But on the “expanded” (invisible) graph it would look like this:
And from there I would bind another delegate node to execute “On Event” just like the _BaseAsyncTask does.
I’m confused… Considering this solution, where my server request would be done?
If I understand you well, K2_B is the “This is my brand new node” showed in my first post… If so, how K2_A would get executed?
Yes, I would execute it like an event… Than from code somewhere make a call to the event that fires the exec pin from the node.
The actual code would be your “This is my brand new node”, but it is only an internal _CallFunction node created within ExpandNode(), in Blueprint graph ppl can’t see it.
The “Exec” pin can also be hidden.
You could make a link to event BeginPlay and hide Exec pin on your already done node, would be the same result.
Also, just noticed both UK2Node_CustomEvent and its base parent (UK2Node_Event) are marked as MinimalAPI. So I guess won’t be able to use them as base classes, correct?
PS: hahahahaha… I hadn’t seen your answer by the time I posted this question!
Thanks a lot for your kind help, @BrUnO_XaVIeR!
Wow! I understand now, that’s pretty clever!
However, I’m wondering if it would work for my specific case.
My custom node is provided as a plugin and I don’t have access to the games where the node is going to be used. Yet, the server request needs to be done from inside the game, at begin play.
From where could I call the event, if I don’t have access to the game?
The problem here is that we often use many of these custom nodes at the same time in a single blueprint. This sometimes yields a huge “begin play + sequence” spaghetti, as I can’t have more than one BeginPlay node inside a single blueprint.
This spaghetti is what I’m trying to avoid by removing the input pin!
If it’s for a plug-in then I’m not sure.
I would probably stay with the callable the way it is and expect user to use the node like a function.
I understand… Thanks anyways, [USER=“434”]BrUnO XaVIeR[/USER]! I’ll keep digging to see what else I can find.