Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

GetVertexColorData() not working on packaged build?

Here's what I want to achieve: I have a flat mesh where I want to instanced a static mesh on each vertex. Additionally, I want to use the vertex color of this mesh to handle the rotation and scale of the instance.

All of this is working fine in the editor. Here's what it looks like:

alt text

My problem is that I am not able to properly get the vertex color in a packaged build (or when launching it). I am using a C++ Blueprint library to do this. Extending from the function shared by Rama (wiki), I have the following code:

 bool UMultivrsBPLibrary::GetStaticMeshVertexInfo(UStaticMeshComponent* SM, TArray<FVector>& VertexPositions, TArray<FColor>& VertexColors)
 TMap<FVector, FColor> VCMap;
 for (int i = 0; i < VCMap.Num(); i++)
     FColor c = VCMap[VertexPositions[i]];

Is the GetVertexColorData() function not working outside the editor? Is there an other/better way to get the vertex color in blueprint? By the way, the position is still correct but the vertex color is completely black. I have been able to confirm this by doing a Print.

I would appreciate any help on this!

Product Version: UE 4.14
more ▼

asked Feb 02 '17 at 02:57 PM in Packaging & Deployment

avatar image

115 3 4 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hello CapitaineStar,

From looking up the GetVertexColorData function in StaticMesh.cpp, it looks like the entire body of the function, other than the first line which sets it to an empty value, is contained in "#if WITH_EDITOR" meaning that it will only execute in the editor.

From looking up alternatives, I came across this old archived post that may be able to provide some information. It looks like there are no plans to expose this information to blueprint but you may be able to access it in C++ by directly accessing a Static Mesh's FColorVertexBuffer variable.

more ▼

answered Feb 07 '17 at 08:00 PM

avatar image CapitaineStar Feb 07 '17 at 10:45 PM

Hello Matthew,

This is exactly what I ended up doing!

Here's the code for anyone that would need it:

 #include "StaticMeshResources.h"
 bool UMultivrsBPLibrary::GetStaticMeshVertexInfo(UStaticMeshComponent* SM, TArray<FVector>& VertexPositions, TArray<FColor>& VertexColors)
     if (!SM)
         return false;
     if (!SM->IsValidLowLevel())
         return false;
     FPositionVertexBuffer* VertexBuffer = &SM->GetStaticMesh()->RenderData->LODResources[0].PositionVertexBuffer;
     FColorVertexBuffer* ColorBuffer = &SM->GetStaticMesh()->RenderData->LODResources[0].ColorVertexBuffer;
     if (VertexBuffer)
         const int32 VertexCount = VertexBuffer->GetNumVertices();
         for (int32 Index = 0; Index < VertexCount; Index++)
             // Converts the UStaticMesh vertex into world actor space including Translation, Rotation, and Scaling
             const FVector WSLocation = SM->GetOwner()->GetTransform().TransformVector(VertexBuffer->VertexPosition(Index));
             const FColor Color = ColorBuffer->VertexColor(Index);
     return true;

The other really important thing here is to enable Allow CPUAccess on your Static Mesh settings.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question