top of page

Tutorial: Dynamic Assets in UE4

Contents

Contents

Introduction

Part 1 | Setting Up Your Assets

Setup

Creating Sockets in Unreal

Part 2 | Creating a Customisable Asset - Adding Text

Setting up the Blueprint

Creating Variables

Creating the Script

Part 3 | Creating a Customisable Asset - Adding Light

Adding the Light

More Variables

Adding to the Script

Conclusion

Introduction

This tutorial will go over some ways you can utilise static mesh sockets to create customisable assets for your scene. To demonstrate, I will be using a train signal that has a nameplate and one light as an example.

The initial idea for this came from creating my own content for a simulator called “Trainz Simulator 2012” (by N3V). There is a system in place where you can add attachment points to the mesh and then use these to add effects such as smoke or even text. This has been a useful part of creating assets for this game and so I decided to adapt the process for Unreal Engine.

The tutorial is broken up into three parts, each one building upon the last. The first part will go through setting up the asset and importing it into UE4. The second and third parts will go through setting up a blueprint that will allow us to use these assets as well as add other parts to the mesh.

Part 1 | Setting Up Your Assets

Note: Throughout this tutorial, I will be adopting some of the naming conventions I used when originally creating the asset for Trainz.

Setup

There are two ways we can add attachment points to static mesh assets. The first way is to add them before exporting and the second way is to add them once they are in engine. I will cover both methods, starting with the first way.

Open your asset up in the modeling program (I have used Maya 2016). Create a locator or null object. Rename this to SOCKET_a_name0. The first part of the name (“SOCKET_”) is used to tell UE4 that this object will be used as a socket. Once imported it is dropped from the name and will just show up as “a_name0”. This locator will be used to place text on the object when it is in engine. Move the locator into position, make sure you place it just in front of the area you want the text. If it is directly on top of the face you will see “Z fighting”.

Export the asset as an FBX and import it into Unreal.

Creating Sockets in Unreal

Open up the static mesh and go to Window > Socket Manager. This will open up a tab on the left that lists all the sockets. You should see the a_name socket appear in the list. To visualise this in 3D space, click on the socket icon. It will be along the top of the 3D view. This shows the sockets in their locations on the mesh. This brings us to the second way of creating sockets.

Underneath the list of sockets there are two buttons, one for creating and one for deleting sockets. Create a new socket and call this a_light0. Move this into position, just in front of where you want the light to be. You can move the socket using the manipulators in the preview window or by adjusting the values in the socket manager. You should now have something that looks similar to fig. 1.1.

Save the mesh and go back to the content browser. Keep the mesh tab open though as we will need to come back and edit the sockets later. We are now ready to move onto the next section.

Part 2 | Creating a Customisable Asset - Adding Text

This next part will deal with setting up the blueprint so that we can add a custom name to the asset and have it appear on the nameplate.

Setting up the Blueprint

Create a new Actor Blueprint class. For mine, I have named it blp_signalCustom so that I know this blueprint is for signals and that it is customisable.

Open up the blueprint. For this first part we will need three components. The first will be a “Scene” component to act as the root. The second will be the static mesh and the third will be the text.

Add a new scene component (it will replace the default one there) and call this root. This just acts as the ‘parent’ for the other components. With this selected, add a new static mesh component. This will be the mesh used for the sign or signal. Call this mesh0. The final component will be the text. Add a new “Text Renderer” component and call it text0. You should now have something like fig. 2.0 in your hierarchy.

Both the mesh and the text will be driven by variables, so that we can customise them. We will however set up some defaults for them, so that we can see what we are doing. Select the mesh you want to use. For the text, I like to have the text the same as the components name so that I can easily see which one is which (if there are multiple) in the viewer. It is up to you though what you put. You will want to set the vertical and horizontal alignment to be centered. If you like, set the world scale as well. This is the size the text will appear in the word.

Creating Variables

Now let's setup the variables to drive these components. We want to be able to change the mesh, change what the text says and also change the size and colour to better suite the look of the sign it is used on.

First one will be the mesh. Add a new static mesh variable and call this BaseMesh. Tick the box that says ‘editable’ and also give it a meaningful tooltip. Adding a tooltip will help you (or someone else using the blueprint) know what mesh this is for. We will also add a custom category to group this under. Type in “Mesh Components” where it says “Default”. We can leave the mesh blank for now as the static mesh component already has its default.

The second variable needed is for the text. Add a new variable and call it text0_Name. Make sure it is a string variable and is set to public. Again we will give it a meaningful tooltip (for mine I put “Text to be displayed “a_name0”). Also add another custom category called “Text”.

The final two variables will control the size and colour of the text. Add a new float variable, set to public and call it text0_Size. Give it a tooltip and set the category to be “Text”. You will want to edit the default size for this as well (set to 12 for now). For the colour, create a new variable and call it text0_Colour, set to public and change the type to be “Linear Color”. Also set the default colour to white with no transparency (i.e all values set to 1). Add it to the text category.

Now we have the components and their respective variables set up, we need to connect them. Switch to the construction script tab for the blueprint. The first node we create will be a sequence node. This will split the output up, so that we can do multiple parts at the same time.

Creating the Script

Drag in mesh0. Off this drag a connection out and search for “set static mesh”. Use the one that gets highlighted. Holding the control key, drag in BaseMesh and connect this to the new mesh input of the “Set Static Mesh” node. Connect up the execution pin.

Next, drag in the text0 component. Off this drag a connection out and search for “attach” (select the first one). The parent will be mesh0 so connect this from the one already in the graph. The socket name will be “a_name0”. Also change the attach type to be “Snap to Target”.

Again, drag a connection off the text0 component and search for “set text”. Connect the text0_Name variable to this. Drag a third connection off the text0 node and search for “set color”. Connect the text0_Colour variable to this. Note that it is not directly compatible but will automatically make a conversion node. Lastly drag off a final connection from the text0 node and search for “set size” and connect the text0_Size variable to this. It should look something like the image below.

You should now be able to compile and save the script, and view it in the editor (or preview window of the blueprint). Depending on which way your model (more specifically the socket) was oriented, the text may not be facing the right direction. Simply go back to the mesh tab and open up the socket manager. Rotate the name socket’s yaw until the X-axis is facing out.

Save and check the blueprint again (you may need to save the blueprint first to see any change). Now you can rename your sign to anything you want, change the size and the colour as well.

Part 3 | Creating a Customisable Asset - Adding Light

The final part of this tutorial series will go over adding a light to the asset. When we set up the mesh before, we added the socket “a_light0”. This will be used in much the same way as the “a_nam0” attachment point, but instead of adding text we will attach a point light.

Adding the Light

Open up the blueprint again. Add a new point light component and call it light0. Depending on the use of the asset you might want to change some settings. For me, I know that this particular setup will be used for a train signal, so I don’t need the light to cast shadows or have a large attenuation radius. You could of course set it up that these are editable later, but that is beyond the scope of this tutorial. There are some settings we will be making customisable. The colour, and intensity will be controlled via variables, similar to the the way we set up the text.

More Variables

Create a new float variable, call it light0_Intensity. Make it public and give it a meaningful tooltip. For now, you might want to set the default value to be 5000 (this is the light default). Add this to a new category called “Light”.

Create another variable, this time a Linear Color variable and call it light0_Colour. Make it public, set the tooltip and defaults and add it to the light category.

The final variable we will create will be a boolean. This will be called light0_Use. Set it to public, give it a tooltip and add it to the light category. By default it will be checked on. This variable will control whether or not the light is on or not.

Adding to the Script

Now we need to connect these up to the construction script. Switch to this tab and add another pin to the sequence node. Drag in the light0 component. Off this drag out a connection and search for “attach to”. Set this up the same as the other attach node but instead of the socket “a_name0” we will use “a_light0”.

Drag a second connection off light0 and search for “set visibility”. Connect the light0_Use variable to the “New Visibility” input. Next drag another connection off light0 and search for “set intensity”. Connect the light0_Intensity variable to the “New Intensity” slot. Lastly, drag another connection off light0 and search for “set color”. Connect the light0_Colour variable to this. Make sure all the execution pins are connected.

You can now compile and save the script. Place one in your scene and you will be able to edit the name, font colour, font size, light intensity etc.

Conclusion

There are many uses for this type of system. You could add more attachment points for lights and text, but also add points for adding other mesh assets (for example to change the type of sign that appears on the post).

Featured Posts
Recent Posts
Archive
Search By Tags
No tags yet.
    bottom of page