Blueprint Functions Plus Custom Input/Output Pins

  Unreal Engine 5 Documentation - Functions


Functions are node graphs belonging to a particular Blueprint that can be executed, or called, from another graph within the Blueprint.

1. Inside the Content Browser, click the New Button then select Blueprint Class.  

2. In Pick Parent Class window, select Actor

3. Name the Blueprint, then Double-click on it to open it up in the Blueprint Editor.

4. Right-click in the graph and search for and add the Event Begin Play Event. This node will execute once when the game is launched, along with any script that follows it. 

5. Right-click in the graph and search for and add the Get Player Controller node.  This will get the currently assigned player controller and allow us to Enable Input for this Blueprint. 

6. Right-click in the graph and search for and add the Enable Input node. This is the node which will allow input to be received for this Blueprint. 

7. Connect the Event Begin Play Node's out exec pin to the in exec pin of the Enable Input Node. Then, connect the Get Player Controller Node's "Return Value" out pin to the Enable Input Node's "Player Controller" in pin. When the game is launched, we get the player controller and enable input from it in this Blueprint.

8. In the MyBlueprint window, click the Add New Function button. 

9. Select the new function in the My Blueprint window and press F2 to rename it. Give the Function a name such as "Print Text"

10. In the Function's graph, drag off the Print Text pin and search for and add a Print String node.  

11. In the In String box of the Print String node, you can leave or change the text to the text you want to display in-game. 

12. Click the Event Graph tab to return to the Event Graph. 

13. Right-click in the graph and search for and add an F Key Event. 

14. Drag off the Pressed pin and search for and add your Print Text function. When F is pressed, it will call the Print Text function which is set to print text to the screen using a Print String.(NOTE: If you do not see your function, try clicking the Compile button from the Toolbar then try your search again.)

15. Your network should look similar to below. 

PrintText Function:

 
 

Event Graph:




16. Click the Compile button then close the Blueprint.  

17. Drag the Blueprint into the level, then click the Play button to play in the Editor. 

18. Press F and the Function will be called and print your text to the screen. 


Input/Output Pins

   When selecting your function in the My Blueprint panel, over to the right in the Details panel you can add Inputs and Outputs. You can press the add button to add input and/or output pins and it's like adding new variables. You name the added input or output and then select it's data type from the drop-down list. So expanding with the above example with Print Text. I added a string input and an integer output. As you see in the picture below the Print Text gets a string output pin. When we add outputs, a new Return Node is created and adds any outputs we ant for our function in the input pins of the Return Node. I've also added a Len Node to get the length of the string to return as an integer.


   Compile/Save, then go back the Event Graph. I have a string variable set to "Hello World" in it's Details panel connected to the Sting input of the Print Text function. I've added a new Print String Node and connected it to the "String Length" output pin of the Print Text Node. That created a conversion node in between them converting the output integer into a string.

   It prints "Hello World" first. Then, it prints 11 for the number of characters in the string containing "Hello World".