Category

Game

UE4 Blueprint Introduction

By Game, UE4

Creating our First Blueprint in a Single Click.

  • Make sure you have the target object selected in the World Outliner panel, and click on the blue Blueprint/Add Script button at the top of the Details panel. You will then see a path select window.
  • Choose Blueprints in the Blueprints folder, inside the ThirdPersonBP folder.
  • To open the Blueprint editor, double-click on this Blueprint in your Content Browser > ThirdPersonBP > Blueprints or with the Blueprint actor selected in the World Outliner open it with Ctrl-E or RMB > Edit …

Detecting a Hit

  • Click on the Event Graph tab above the Viewport window and delete all the default items.
  • To create our hit detection event, right-click on empty graph space and type hit in the search box. Select the Event Hit node when it appears in the search results to bring it on the empty slate. Event Hit triggers actions every time another actor hits the actor controlled by this Blueprint.
  • The Event Hit node has a number of output pins. The white triangle pin in the top-right corner of the node is the execution pin, which determines the next action to be taken. Now that we have the trigger, we need an action that changes the material. Click and drag a wire from the execution pin to empty space to the right of the node. In the search window that appears, make sure that the Context Sensitive box is checked. This will limit the results in the search window to only those nodes that can actually be attached to the pin you dragged. Type set material in the search box and select Set Material (StaticMeshComponent).

Swapping a Material

  • Once you have placed the Set Material node, it is already connected via its input execution pin to the Event Hit node’s output execution pin. This Blueprint will now activate the Set Material action whenever the Blueprint’s actor hits another actor. To set up the material that will be called when the Set Material action is on, make a copy of the initial material and change the colour, texture, etc.
  • In the Blueprint click on the drop-down field labeled Select Asset underneath Material inside the Set Material node to set the new material. In the asset finder window that appears, scroll to find the new material, click to attach it to the Material field inside the Set Material node.
  • Before a Blueprint can be saved and used, it must be compiled. Hit the Compile button in the top-left corner of the editor toolbar, and then click on Save. To test the Blueprint click on the Play button and try running into the actor you created.

Change the State on Leave (Begin / End Overlap)

  • With this hit detection setup the actor remains in the triggered state after the hit. If we want it to return it to it’s default state and have more control over how and where the collision happens, we can use the Begin / End Overlap nodes instead of the Event Hit. In our Blueprint delete the Event Hit node. In the Components tab choose > Add Component > Box Collision.
  • Switch to the Blueprint’s Viewport and move, scale, rotate the Box Collision to match the actor’s geometry. Switch back to the Event Graph. With the Box still selected go to the > Details tab > Events and click + at On Component Begin Overlap and On Component End Overlap. Connect the execution pin of the On Component Begin Overlap node with the execution input of the existing Set Material node.
  • Copy Paste the Set Material node and change the material in the pasted node to the default or another material. Connect the Static Mesh Component node with the Target input of the Set Material node. Connect the execution pin of the On Component End Overlap node with the execution input of the second Set Material node.

Adding Movement

  • To allow our target to move, we first have to change the actor’s Mobility setting to Moveable. This allows an object to be manipulated while playing the game. In the Blueprints window with the Static Mesh Component (Inherited) selected look at the Details panel. Underneath the Transform values, you can see a toggle for Mobility. Change this from Static to Moveable.
  • RMB click on the event graph canvas and type in > Add Rotating Movement Component. If you want to have a permanent rotation, RMB click and type Event BeginPlay. Connect the white triangle of Event BeginPlay with the white triangle input of the Add Rotating Movement Component.
  • If you want to use a trigger object instead, connect the output of the On Component Begin Overlap with the input of the Add Rotating Movement Component.
  • With the Add Rotating Movement Component selected you can change the speed at the Details tab > Rotation Rate. If you want to translate your actor, you can use the AddActorLocalOffset node.

Recording Gameplay with the Sequencer

  • In the top toolbar choose > Cinematics > Add Level Sequence. Specify a name and path. It will then show up in the World Outliner.
  • If there is a Camera Cuts track in the Sequencer, delete it. Create > + Track > Camera Cut Track. In this track add  a > + Camera. From the dropdown menu select the ThirdPersonCharacter as camera and make sure it covers the whole timeline.
  • If you closed your UE4 project and want to continue working with the Sequencer you need to RMB click on the sequence in the World Outliner and choose > Edit LevelSequence or press CTRL-E (double click doesn’t work here).
  • In the sequencer window click on the clapper board icon to open the Render Movie Settings Menu.
  • Use Video Sequence as Output Format, change Frame Rate and Video Resolution, disable Use Compression to avoid compression artefacts.
  • In the Cinematic tab make sure > Allow Movement, > Allow Turning, > Show Player are checked.
  • > Capture Movie and then use the WASD keys to navigate to the hotspots you have created.
  • Convert the output .avi file with Adobe Media Encoder to .mp4.

Importing a Maya Blendshape Animation Into UE 4

By Game, UE4

Create a Blendshape animation in Maya and import it into UE4. Create a screencast with the Sequencer.

For making blendshapes work, the number and structure of vertices must not change during the animation. Start with a simple cube to sphere morph as described below or you can use any other (simple) geometry for the animation.

Creating a Blendshape in Maya

  • In Maya > Create > Polygon Primitives > Cube and in the Modeling Toolkit > Add Divisions 2 times. Rename it to “cube”. Apply a texture map.
  • Duplicate this Object in the Outliner (CTRL-D) and rename it to “target”. Hide the first cube with the h key. Now > Create > Polygon Primitives > Sphere, rename it to “helper” and scale it smaller, so that it’s completely covered by the cube.
  • First select the “target” and then the “helper” and in the Modeling menu set select >  Deform – Create > ShrinkWrap [options]. Make sure > Projection > Toward Inner Object is selected, click Apply. The former “target” cube should have now a spherical shape and lie inside the “helper” sphere. You can hide the “helper” with the h key (don’t delete it yet).
  • With the “target” selected > Edit > Delete by Type > History. Now you can delete the “helper” object.
  • Unhide the first cube with the “h” key. Select the “target”, scale it up to roughly equalise the cube’s and the sphere’s volume. With the “target” and the “cube” selected > Modify > Freeze Transformations.
  • Select first the “target” and then the “cube” (the morph’s initial state is selected last), select >  Deform – Create > Blend Shape [options]. Make sure that Check topology is marked, click Create.
  • Hide the “target”, but don’t delete it. With > Windows > Animation Editors > Shape Editors or in the blendShape tab at the Attribute Editor you should be now able to change the target weight, so that the shape morphs from cube to sphere. Set a keyframe at frame 0 with a target weight of 0 and at frame 200 with a target weight of 100.
  • With the “cube” selected go to > Mesh Display > Soften/Harden Edge [Options] type in an angle of about 45 and > Apply. This softens the edges in accordance with the state of the shape.

Exporting the Blendshape from Maya as FBX file

  • With the “cube” selected > File > Export Selection … In the FBX Exporter dialog make a tick at > Geometry √ Tangents and Binormals, at > Animation √ Animation and at > Deformed Models √ Deformed Models, √ Skins and √ Blend Shapes.

Importing the FBX file into UE 4

  • In UE4’s Content Browser select > Import. In the FBX Import Options make a tick at √ Skeletal Mesh. Expand the > Mesh tab and check √ Import Morph Targets and at > Normal Import Method choose Import Normals and Tangents. Make sure that Animation is checked and change at > Transform > Import Uniform Scale to 100 if you haven’t scaled your model in Maya yet.
  • From the Content Browser open the newly imported Animation Sequence (filename_Anim). Due to a bug in UE 4.17.1 the Blendshape animation might not work yet. To fix it, select the imported Skeletal Mesh in the Content Browser and with RMB choose > Reimport.

Exporting the Blendshape from Maya as Alembic file

  • With the cube selected go to > Cache > Alembic Cache > Export Selection to Alembic [Option].
  • At > Advanced Options you need to check √ UV Write and √ Write UV Sets. Export Selection.

Importing the Alembic file into UE 4

  • In UE4’s Content Browser select > Import. Make sure that in the Alembic Cache Import Options at > Alembic > Import Type > Skeletal is selected. Recompute Normals should be deselected. > Conversion > Scale your model by 100 if you haven’t done it in Maya yet. Make sure, the y – scale value remains negative (to compensate the different axis orientation in Maya and UE4).
  • You can double click on the newly created …_Animation asset to see if the animation works. Drag it into your scene.
  • In UE4’s Content Browser select > Add New > Material and rename it. Double click the newly created Alembic Skeletal Mesh node. In the editor at > Material Slots select this material from the dropdown menu.
  • In the Content Browser select > Import and choose the texture file from your drive you want to apply.
  • Double click on the Material. Drag the imported texture onto the Material editor. Connect the topmost white connector from the Texture Sample with the Base Colour connector of your Material node.
  • If you want to change the specularity of the material, create a simple colour node. RMB click, type: const and select Constant3Vector. Connect the output with the Specular input. Duplicate the colour node and connect it with the Roughness input. If you want full specularity, change the colour node at the specular input to white and leave the one at Roughness black. White = 100 % Specular, Black = 0 % Roughness, you can fine tune the specularity values with different greyscale values.
  • Click the > Apply icon on top of the Material Editor. When the Material is assigned to your alembic file, it should show up in the viewport after a while. In case the material disappears while playing the game / animation, save the project and open it again to refresh the texture cache.

Editing with the Sequencer

  • Go to the Modes Window / Tab and from the Basic tab drag an empty actor into the viewport. This creates a null object which we ca use for a simple camera rig to let the camera rotate around. Move it to the focal point in your scene and in the World Outliner give it a meaningful name.
  • In the Modes Window / Tab type “cam”. Select the simple Camera on top of the list and drag it into the viewport. While the camera is selected you get an preview in the viewport. Move the camera until you are satisfied with the framing.
  • In the World Outliner drag the Camera onto the null object to make it a child of the null.
  • In the top toolbar choose > Cinematics > Add Level Sequence. Specify a name and path. It will then show up in the World Outliner.
  • If there is a Camera Cuts track in the Sequencer, delete it. Create > + Track > Camera Cut Track. In this track add  a > + Camera. From the dropdown menu select the camera you want to use and make sure the track covers the whole timeline.
  • You could also add different cameras and control with their track duration in the Sequencer which camera will be used in the final animation.
  • To animate the rotation of the camera around the focal point, drag the null object into the Sequencer. Expand it’s > Transform > Rotation tabs and by clicking on the little circle set a keyframe at frame 1 for the z value (in UE4 the axis are flipped, Maya’s y axis is equivalent to UE4’s z axis). Go to the end of the animation and type in 170 for z. A keyframe will be created automatically.
  • You might have noticed that values beyond +/- 180 degrees are not accepted here. In the the top menu of the Sequencer on the right click the animation curve icon to show the animation keys in a curve editor. When you select the key there, you can type in any value without restriction.
  • If you close your UE4 project and want to continue working with the Sequencer you need to RMB click on the sequence in the World Outliner and choose > Edit LevelSequence or press CTRL-E (double click doesn’t work here).

Exporting the Animation

  • In the sequencer window click on the clapper board icon to open the Render Movie Settings Menu.
  • Use Video Sequence as Output Format, change Frame Rate and Video Resolution, disable Use Compression to avoid compression artefacts.
  • In the Cinematic tab make sure Cinematic Mode and Cinematic Engine Scalability are checked.
  • > Capture Movie and convert the output .avi file with Adobe Media Encoder to .mp4.

Quick Tips

  • Improve shadow quality and remove the preview mark on materials: Select Light Source and in the Details pane select  > Transform > Mobility > Movable (instead of Stationary).
  • Enable precise physical interactions (e.g. walk on a terrain): In the content browser select the Static Mesh asset. Double click it to open the Editor window. In the Details tab at > Collision > Collision Complexity choose from the popup menu > Change Complex Collision as Simple.
  • Avoid Intersection with other actors: Double click on the static mesh to open the asset editor. At the Details tab scroll down to > Collision and at > Collision Presets choose > BlockAll.