Blueprints

Blueprints in Unreal is a C++ based visual scripting language built proprietary to Unreal. Blueprints will allow us to create code without the need to touch a line of text in an IDE such as Visual Studio. Instead, Blueprints allows us to create code through the use of drag and drop visual nodes, and connect them together to create nearly any kind of functionality you desire. Those of you who have come from UDK may find some similarity between Kismet and Blueprints, but unlike Kismet, Blueprints allows you to have full control over the creation and modification of functions and variables. It also compiles, which is something Kismet did not do.

Blueprints can inherit from C++ classes, or from other Blueprints. So, for instance, you might have an Enemy class. An enemy might have a Health field, a Speed field, an Attack field, and a Mesh field. You can then create multiple enemy templates by creating Blueprints that inherit from your Enemy class and changing each type of enemy's Health, Speed, Attack, and Mesh.

You can also expose parts of your C++ code to Blueprint graphs so that your Blueprint graphs and your core game code can communicate and work with each other. As an example, your inventory code may be implemented in C++, and it might expose functions to Blueprints so that a Blueprint graph can give items to the player.

Creating a new Blueprint

The steps to create a new Blueprint are as follows:

  1. In the Content Browser pane, create a new Blueprint folder by clicking on the Add New drop-down list and selecting New Folder, then renaming the folder Blueprint. Inside this folder, right-click and select Blueprints | Blueprint Class. Select Actor as the parent class for the Blueprint.
  2. Next, give a name to your new Blueprint, such as MyNewBlueprint. To edit this Blueprint, double-click on its icon in the Content Browser tab.
  3. Next, switch to the Event Graph tab.
  4. If Event Begin Play is not already there, right-click on the graph and expand Add Event; then, click on Event Begin Play. If you ever need to move around nodes such as Event Begin Play, you can simply left-click on the node and drag it anywhere on the graph you want. You can also navigate through the graph by holding down the right-click mouse button and dragging across the screen:
    Creating a new Blueprint

    This will add a new event node to the graph.

  5. Next, right-click and begin typing print into the search bar. You should see the Print String option in the list. Click on it to add a new Print String node to your graph.
  6. Next, we want to have this node triggered when the Event Begin Play node is triggered. To do this, drag from the output arrow of the Event Begin Play node to the input arrow of the Print String node:
    Creating a new Blueprint
  7. Now, the Print String node will be triggered when the game begins. However, let's take this one step further and add a variable to our Blueprint.
  8. On the left-hand side in the My Blueprint pane, click on the Variable button. Give a name to your variable (such as MyPrintString) and change the Variable Type drop-down list to String.
  9. To feed the value of this variable into our Print String node, right-click and search for MyPrintString. You should see a Get My Print String node available in the list. Click on this to add the node to your graph:
    Creating a new Blueprint
  10. Next, just as you did to connect Event Begin Play and Print String together, drag from the output arrow of the Get My Print String node to the input pin of the Print String node that is right next to the In String label.
  11. Finally, switch over to the Defaults tab. At the very top, under the Defaults section, there should be a text field for editing the value of the MyPrintString variable. Enter whatever text you'd like into this field. Then, to save your Blueprint, first press the Compile button in the Blueprint window and then click on the Save button next to it.

Adding a Blueprint to the scene

Now that you've created the Blueprint, simply drag it from the Content Browser tab into the scene. Just as with our custom actor class, it will be invisible, but if you scroll Scene Outliner to the bottom, you'll see the MyNewBlueprint item in the list.

To test our new Blueprint, press the Play button. You should see that the text you entered is briefly printed to the screen (it will also show up in the Output Log, but it may be difficult to spot amidst the other output messages).

Blueprints for Actor classes

You can choose other classes for a Blueprint to inherit from. For instance, let's create a new Blueprint to inherit from the custom MyNewActor class we created earlier:

  1. To do this, start creating a new Blueprint as before. Then, when choosing a parent class, search for MyNewActor. Click on the MyNewActor entry in the list:
    Blueprints for Actor classes
  2. You can name this Actor whatever you want. Next, open the Blueprint and click on Save. Now, add the Blueprint to your scene and run the game. You should now have two Hello, world! messages logged to the console (one from our placed actor and the other from our new Blueprint).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.119.81