Announcement

Collapse
No announcement yet.

Creating custom UK2Node that executes without input exec pin?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Creating custom UK2Node that executes without input exec pin?

    Hello!

    Context
    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:

    Click image for larger version  Name:	node-with-input.png Views:	0 Size:	11.1 KB ID:	1781333

    In this case, I use the input exec pin to make the server request. Everything works beautifully!

    Problem
    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:

    Click image for larger version  Name:	node-no-input.png Views:	0 Size:	11.0 KB ID:	1781334

    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?
    Last edited by Tapioca Dreams; 06-26-2020, 03:59 PM.

    #2
    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.
    | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

    Comment


      #3
      Obrigado, BrUnO XaVIeR! 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?

      Comment


        #4
        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.
        | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

        Comment


          #5
          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?

          Comment


            #6
            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.
            | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

            Comment


              #7
              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!
              Last edited by Tapioca Dreams; 06-29-2020, 04:22 PM.

              Comment


                #8
                Thanks a lot for your kind help, @BrUnO XaVIeR!

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

                You could make a link to event BeginPlay and hide Exec pin on your already done node, would be the same result.
                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!
                Last edited by Tapioca Dreams; 06-30-2020, 10:27 AM.

                Comment


                  #9
                  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.
                  | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                  Comment


                    #10
                    I understand... Thanks anyways, BrUnO XaVIeR! I'll keep digging to see what else I can find.

                    Comment

                    Working...
                    X