segunda-feira, 7 de abril de 2014

Creating the first Class Blueprint

In this article we will create a simple class Blueprint to learn the basic steps of the blueprint editor. There are two ways to create a class Blueprint. One of them is using the "Content Brower". Just select the "New-> Blueprint" option as shown in the image below.

The other option, which is the one we will use, is located at the top of the main editor. Click the "Blueprints" button and then select "New Class Blueprint ...".

On the next screen we must select the parent class that we will base our new Blueprint. For now, think of the parent class as if it was the type of the Blueprint. Select the "Actor" option.

In the following screen you can enter the name of your new Blueprint and choose the folder where it is created. I chose the name "HelloUnreal" and the Blueprints folder. The name of the Blueprint can not contain white space or special characters.

After this the blueprint editor will open containing our new Blueprint. Switch to the "Graph" mode using the option that is in the top right.

Our first script will write the message "Hello Unreal" on the screen when the game starts. To do this we will need an Event and an Action.

It's through Events that Unreal Engine 4 can tell our Blueprint of what's happening in the game. We use Actions to define what the Blueprint should do when a certain Event happens.

The event that we will use is the "Begin Play". To add it to the Blueprint right click on the center of the "EventGraph" and select the option "Add Event -> Event Begin Play".

Now let's add the Action that will write the text on the screen. Right click on the "EventGraph" and write the word "print" in the search box. Choose the "Print String" option as shown below.

The action "Print String" has a parameter called "In String". This is the text that will be written on the screen. In my example I put the text "Hello Unreal". Connect the white pins between the Event and the Action. Your "Graph" should look like this:

For our Blueprint becomes valid we must compile it by pressing the button which is on the upper left. If there is no error in the Blueprint, the "Compile" button will show a green icon indicating that everything is OK.

We need to add this Blueprint to the current level. Return to the main editor of the Unreal Engine 4. Go to the Content Browser, select the Blueprint that was created and then right click anywhere in the level. Choose the "Place Actor" option that contains the selected Blueprint.

The "Scene Outliner", which is on the right of the main editor, contains references to Actors that are part of the current level. The Blueprint added to that level will appear in this list.

To test the Blueprint, use the "Play" button that is on the top of the main editor.

The message "Hello Unreal" will be written on the top left of the screen and then disappears.