Misc

  • Enable Input
    • By default the key input is disabled in the standard template.
      • This is why we need to enable Input in the BeginPlay event
    • In a level blueprint we do not need to do this
  • Consume Keyboard event
    • By default a keyboard event has the property “Consume” enabled
      • if it is enabled it will prevent actors with a lower priority to handle the input
  • Logic Sequence (Flow Control)
    • If you want to call n number of functions from one input you can use the “Sequence” (Flow Control) node. This allows multiple chains of logic to be called in a sequence.

UI

Level BP HUD

Lets create a HUD that gets added in the level bp.

  • Create the UI Widget
    • Content Browser > RMB > User Interface > Widget Blueprint
      • Lets call it “HUD”
      • Double click to enter the widget
    • Add Text Widget
      • From the Palette drag out a Text widget
        • To keep it sinmple we will only add a text widget
      • With the text widget selected, in the details panel at the top give it the name “MyText” and enable the “Is Variable” (This is importatnt if we want to set the value at runtime)
      • Compile and save
    • Add an update function
      • Switch to the “Graph” section (by clickeing the button top right corner)
      • In the “MyBlueprint” panel under the “Functions” section add a new function and call it “UpdateHUD”
      • Add an input top the function
        • With the “UpdateHUD” function node selected, in the details panel click the plus icon in the “Inputs” section to add an input. Call it “Name” and set the datatype to “Text”
      • Click compile and save
      • From the “MyBlueprints” panel drag out “MyText” variable to the graph (of UpdateHUD function) select “Get (MyText)”
      • From the output pin of the Get MyText drag release and start typing “set tex…” select “(Widget) Set Text (Text)”
      • Connect the output execute pin of the “Update HUD” function node to the input execute pin of the set text node
      • Also connect “Name” to “In Text”
      • Click compile and save
  • Add the Widget to viewport
    • Open the level blueprint
    • From the “Event BeginPlay” drag out the execute pin release and start typing “create w” select “User Interface : Create Widget”
    • In the “Class” input dropdown select “HUD” (The widget BP we created earlier)
    • Lets promote the widget so we can use it elsewhere in the event graph
      • On the “Return Value” of the Create Widget node RMB > “Promote to Variable”
    • From the “Return Value” output pin (of the “Set” variable node) drag out, release and start typing “add to…” select “Add To Viewport”
  • Update HUD
    • In this test example we use the level bp to print some dummy text to the vieport. We listen for a keyborad event and the print some text. Instead lets use our hud to display this text.
    • From the “MyBlueprint” panel under the “Variables” drag out the “HUD” varaiable and cjhoose “Get”
    • From the blue output pin drag out and release and start typing “up…” select “UpdateHUD” (The function that we made earlier)
    • Then we simply connect the input execute pins of the keyboard event aswell as the text input. We now have our hud spiplay the text.

Configure Mouse Click on actor

Player Controller

  • Player Controller
    • Create player controller bp
      • Content browser > RMB > Blueprints > Blueprint Class (Based on PlayerController)
        • Under the all classes you can use the input field to search for classes to base the bp on
        • Lets call it PC_configurator
    • Double click to open the player controller
    • Edit mouse properties
      • In the details panel > Mouse Interface
        • Show Mouse Cursor : Enable
        • Enable Click Events : Enable
        • Enable Touch Events : Enable
        • Enable Mouse Over Events : Enable
        • Enable Touch Over : Enable
    • Compile and Save

Game Mode

  • Game Mode
    • Create the game mode bp
      • Content browser > RMB > Blueprints > Blueprint Class (Based on GameMode)
        • Under the all classes you can use the input field to search for classes to base the bp on
        • Lets call it GM_configurator
    • Double click to open the game mode
    • Set the player controller
      • In the details panel > Classes > Player Controller Class
        • Set it to the PC_plauer_controller bp we just created
    • Compile and Save
    • Set the Game mode
      • In the world settings > Game Mode > GameMode Override
        • Set it to the GM_configurator we just created

Camera

  • Camera
    • Add camera
      • From the palce actors drag out a camera amd drop in the view
      • Lets name it “MyCamera”
        • you can do this in the world outliner
    • Place the camera
      • In the “Perspective” drop down top left on the viewport select Placed Cameras > MyCamera and frame the scene in a nice way
      • When you are happy with the camera placement, click the icon to the left side of the “Pilot Active - MyCamera” (below the perspective dropdown)
    • Set the Camera to be used
      • Open the level blueprint
      • In the EventGraph press tab and start typing “get pl…” select “Get Player Controller”
      • From the return value output pin of the Get Player Controller node drag out and release and start typing “set v…” select “Set View Target With Blend”
      • Add the camera
        • From the world outliner drag in the camera we created and drop it in the event graph
      • Connect the camera to the “New View Target”
      • Connect the Event Begin Play execute pin to the input execute pin of the Set View Target With Blend node.

Data tables

  • A DataTable is like a spreadsheet of values that can be fed into inputs in a Blueprint. In this example, we illustrate the process of implementing a simple DataTable.

Simple Datatable

Here is an example of how to setup and use a csv as a datatable source

  • Create a csv file:
    • we will use: (Make sure you have no extra whitespace in the headers)
      ID,Name,Description
      0, Name A, Desc A
      1, Name B, Desc B
      2, Name C, Desc C
      
    • Note
      • The first column will be used as an internal id to look up the rows. The column will internally be named “Row Name” so what you call it in the csv file does not matter. The value used in this column must be unique as it is used as an index but if does not have to be sequential.
  • Create a User defined Struct
    • In the content browser RMB > Blueprints > Structure
      We will use this to let unreal understand the structure of the csv file we are about to read from
      • Lets call it “MyItems”
      • Double click it to open it up
    • The varaibles of the structure represents the columns in our scv file
      • The first column of the csv file is used internally by UE to auto increment and give each row a unique id, so we should not add a variable for that column.
      • Lets call the first variable “Item_Name” and set the datatype to “Text”
      • Lets add a new variable and call that “Item_Description”
  • Import csv file to ue
    • Drag and drop the csv file in the content browser
      • In the “Choose datatable row type” we will enter the “MyItems” struct that we defined earlier.
      • click apply
        • Note if we doulble click the imported csv file we can inspect the data
  • Read the data
    • Lets create a simple blue print that will read and print the data
    • Open up the level blueprint
      • Click the “List of world blueprints” drop down menu (right hand side of to the “Add to Project” buton) ond select Open Level Blueprint
      • (or we could also create a new blueprint if we would like) but if we do so we must make sure input is eanbled, as you can see in the section below “Trigger sequence with key”
    • Add a key input
      • In the Event graph press tab and type “2” select “Keyboard Events 2”
    • Get the datatable row
      • Drag out from the pressed execute pin, start typing “get datat…” select “Get Datatable Row”
      • In the input “Data Table” pin click the dropdown and select the csv file we just imported.
    • Specify which row ro read
      • We will use a random int to select which row to use
        • press trab start typing “rand i” select “Random Integer”
        • Since we 3 rows we set the “Max” input of the rand int to 3 (this will generate a rand int from 0-2)
      • From the return value of the rand int srag out and start typing “tost…” select “To String(Integer)”
      • Connect the output of the “to string” node to the “Row Name” input of the “Get Datatable Row” node
    • Use the Data
      • In our example we will just print the row contents to the screen
      • We could split the “Out Row” struct pin or we could use a “Break” node to do the same in a node instead, lets do the latter.
        • From the “Out Row” drag out and start typing “br…” select “Break MyItems”.
      • Append the columns
        • press tab and start typing “appen…” select “String Append”
        • Connect the outputs that the broke up earlier to the inputs of the append and hook the result up to a print node
          • Remeber to connect the execute pin of the print node
BP_level_blueprint_print_csv
Ctrl-C
A Level Blueprint that reads a csv datatable. Note that you must add variables used in the BP to compile it and also create the csv data table.

Trigger sequence with key

  • Lets add something to animate
    • We will add a simple cube
  • Create a sequence
    • In the top bar click Cinematics > Add Level Sequence
      • Or in the content browser RMB click > Animation > Level Sequence
        • Note: that if you do it this way you have to manually drag it to the viewport aswell
    • If the sequence is not open double click to open in the Sequencer
    • With the sequence selected in the world outliner, in the details panel under the section “Playback” make sure that:
      • “Playback” is set to “Dont Loop” and
      • “Pause at End” is enabled
    • Select the object you want to animate in the world outliner and drag and drop in the sequencer.
      • Or with the object selected, in the Sequencer RMB click > Add Actor to Sequencer > Add ‘Cube’
    • Depending on what you added you might have to add a track
      In our case since we do not have to do this, but if you do not have the track you need to animate do the following:
      • In the sequencer on the right side of the object in the sequencer click the plus button to add a track > Transform (or whatever it is you need)
    • We want to animate the Location Z
      • Expand the Transform and the Location
      • Make sure you are at frame 0 and click the circle at the right side of the Location Z property
      • Move to frame 24, change the location Z of the cube (in the viewport or in the details panel)
        • Alternatively we could enable Auto Key (in the top bar of the sequencer) if this is enabled a key will be set automnatically if a value is changed
    • Set the end of the sequence to the same as the last keyframe (in our case 24)
      • In the righthand side of the sequencer (the time/keyframe area) drag the marker in the top section (the red marker) so that it matches with last keyframe
  • Setup the blueprint
    • Get the Sequence actor
      • In the content browser RMB > Blueprints > Blueprint Class
        • Based on Actor and call it “BP_PlayAnim”
      • Double click to go inside and switch to the EventGraph tab
      • Make sure input is eanbled
        • On the Event BeginPlay, drag out the output execute pin and release, start typing “ena…” select “Enable Input”
        • Press tab and start typing “get pl” select “Get Player Controller”
        • Connect the output pin “Return value” of the “Get Player Controller” and connect it to “Player Controller” input pin of the “Enable Input” node
      • Get the Sequence
        • Drag out the output execute pin of “Enable Input” and release strat typing “get al…” select “Get All Actors of Class”
        • set the input “Actor Class” (of the “Get All Actors of Class” node) to “Level Sequence Actor”
          • This will return an array of level sequence actors, so get the first actor in the array we will use a Get copy node
        • Drag out the “Out Actors” pin (of the “Get All Actors of Class” node) release and start typing “get…” select “Get Copy”
        • We will promote the output of the Get Copy node to a variable so that we can use it elsewhere.
          • RMB click on the blue output pin () > Promote to Variable, call it “MySequence”
        • Then we will connect the output execute pin of the “Get All Actors of Class” node to the input execute pin of the “Set” variable node
    • Trigger sequrnce with input
      • Get the “O” key input
        • press tab in the graph and start typing “o ke…” select the “O” key
      • Enable Flip-flop
        • Drag out from the “Pressed” execute pin of the key event node and start typing “flip flo…” select “Flip Flop”
      • From the variables section in the My Blueprints tab drag out the “MySequence” variable that we promoted earlier choose GET
      • Play
        • From the output pin of the “MySequence” (variable) drag out, release and start typing “play(…” select Play(SequencePlayer)
        • Connect the output execute pin “A” to the input execute pin of the “Play” node
      • Play Reverse
        • From the output pin of the “MySequence” (variable) drag out, release and start typing “rev…” select Play Reverse(SequencePlayer)
        • Connect the output execute pin “B” to the input execute pin of the “Play Reverse” node
      • Make sure to click compile and save
      • Finally we must drag and drop the “BP_PlayAnim” blueprint into the viewport (it will show up in the world outliner)