sexta-feira, 10 de outubro de 2014

Construction Script in Blueprints

This article starts the second part of this blog: "Blueprints Tips".

Let's learn a feature called "Construction Script", which is a special function that all Blueprints have. We can define a set of actions in the "Construction Script" function that will be performed when the Blueprint is added to level and when there is any change in their properties while editing the level.

Let's create an example of a Blueprint that will allow the person who is editing the level to select between three types of "Static Mesh" and select any material to be applied in the Blueprint, without opening the blueprint editor to make these changes.

The first step is to create a Blueprint of the Actor type. Then access the Component mode, add a "Static Mesh" component and put the name "CurrentMesh" for this component. It is not necessary to choose a Static Mesh at this time.

Switch to the Graph mode to create the variables that we will use. First create a variable of type "Material" named "MaterialType". In the "Details" tab, check the "Editable" option and in the "Category" write "Construction Options". 

Then create another variable of type "int" (integer) named "MeshType". Check the "Editable" option and in the "Category" select "Construction Options". On the property "Value Range" write the values ​​"1" and "3". Thus the acceptable values ​​for this integer variable are only 1, 2 and 3. In the "Default Value" put the value "1".

The image below shows the variables that are part of this Blueprint:

The actions in the Construction Script will define the material of the StaticMeshComponent according to the Material selected for the Blueprint in the level editor. After that, the value of the variable "MeshType" is checked to choose one of three Static Meshes that can be attributed to the StaticMeshComponent.

The image below shows the complete "Construction Script":

Click to enlarge

Remember that "CurrentMesh" is a variable that represents the "Static Mesh" component that was previously added. The possible Static Meshs that can be used according to the value of the variable "MeshType" are the following:

1 - Shape_NarrowCapsule
2 - Shape_Cone
3 - Shape_Cube

Add the Blueprint on the Level and modify the values ​​of variables "MaterialType" and "MeshType". The images below show the three types of "Static Mesh" with different materials.

Next: Switchs and Enumerations in Blueprints
Prev: GameHUD: Game Over
Table of Contents