In this post we’re going to see how we can paint vertices during runtime. This post was created with Unreal Engine 4.20 so if you’re using another version you may need to update the code to match Epic’s API for the engine you’re using. It’s worth mentioning that the following code runs in packaged builds as well.

Download the source code from my GitHub repo

Adding the required Dependencies

Before typing any code go into <MyProject>.Build.cs file and add the RenderCore dependency:

Creating the required Materials

In order for our code to work, we need to assign the following material in the static meshes we want to paint. As you may have noticed it’s the same material we’ve used in the “Creating Procedural Meshes” post:

Painting vertices at runtime

To paint all the vertices at runtime, I have created a Blueprint function library with the following public function:

Here is the code that we need to execute in order to paint the vertices of the mesh:

Just for demonstration purposes, I created a Blueprint with a static mesh that has the the M_VertexColors material I created above and inside the Tick function I connected the Static Mesh component with the PaintSMVertices and here’s the end result: