skip to Main Content

Vertex Painting at Runtime

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.

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:

This Post Has 3 Comments

  1. This is pretty amazing.
    One question: I realized, that when you move, scale or rotate the pivot of the object (in the editor), the Vertex Color is overwritten (I guess by the default Color).
    Is there any way to overwrite the color peramently?

    Great Work, thanks, Mirko

  2. Thanks for posting this – I followed along with most of It (not being a C++ coder). When I build and compile it – in Visual Studio – there’s no problems, and the blueprint project builds/compiles as well. However, as soon as I try to run it (in the editor) it crashes straight out of UE4. I’m using UE4.26.1, and I was wondering if you knew whether they had changed any of the code base that would have stopped this from working (and what the problem might be). I updated the build.cs file with the dependency, and built and used the vertex based material. I’d really like to get this working, as it should be very close to what I want to do (I want to have a Line of sight -dependent material (that I will use the vertex color as a mask for).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top