Each time you make a change to a Blueprint (for example you drag it to a different position on your map) it’s construction script runs. This script contains code which is responsible for certain initialization operations. Using the construction script can accelerate certain operations, for example you can create an actor which generates random foliage around a point in your map, thus helping you or your level designer.

In this post, I will create a construction script in C++ which will spawn a given static mesh based on given values around a placed actor. Here is the end result:

Preparing an Actor

Add a new C++ class based on the Actor class and inside the header file, type in the following code:

Switch to your source file and inside your constructor type in the following code:

Compile your code an create a Blueprint based on the class you’ve added above. Then, don’t forget to assign a static mesh to the SM paremeter. Now we are ready to create the actual construction script.

Creating a construction script

Go to the header file of your C++ class and add the following declaration:

After that, switch to your source file and type in the following implementation of the above function:

Please note that you may have to change the name of the class, otherwise you will get a compile error!

That’s it! Go to the UE4 Editor, place the blueprint of your actor and temper with the values we exposed. Of course, you can create an improved version of the above script so the static meshes won’t overlap with each other!