I am having a very strange issue when trying to get the UProceduralMeshComponent to create a mesh.
I copied this “Getting Started” guide and it worked fine.
I have the code as this:
AProcObject::AProcObject() :
{
PrimaryActorTick.bCanEverTick = true;
UProceduralMeshComponent* Mesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("MeshComponent"));
RootComponent = Mesh;
TArray<FVector> vertices;
vertices.Add(FVector(0, 0, 0));
vertices.Add(FVector(0, 100, 0));
vertices.Add(FVector(0, 0, 100));
TArray<int32> Triangles;
Triangles.Add(0);
Triangles.Add(1);
Triangles.Add(2);
TArray<FVector> normals;
normals.Add(FVector(1, 0, 0));
normals.Add(FVector(1, 0, 0));
normals.Add(FVector(1, 0, 0));
TArray<FVector2D> UV0;
UV0.Add(FVector2D(0, 0));
UV0.Add(FVector2D(0, 10));
UV0.Add(FVector2D(10, 10));
TArray<FColor> vertexColors;
vertexColors.Add(FColor(100, 100, 100, 100));
vertexColors.Add(FColor(100, 100, 100, 100));
vertexColors.Add(FColor(100, 100, 100, 100));
TArray<FProcMeshTangent> tangents;
tangents.Add(FProcMeshTangent(1, 1, 1));
tangents.Add(FProcMeshTangent(1, 1, 1));
tangents.Add(FProcMeshTangent(1, 1, 1));
Mesh->CreateMeshSection(1, vertices, Triangles, normals, UV0, vertexColors, tangents, false);
}
So, the only difference is that I have the Mesh as the root object. So far so good. As soon as I move everything below the line
RootComponent = Mesh;
Into a separate function, the editor crashes! I get this error in the log
Access violation - code c0000005 (first/second chance not available)
UE4Editor_ProceduralMeshComponent!TArray<FProcMeshSection,FDefaultAllocator>::SetNum()
UE4Editor_ProceduralMeshComponent!UProceduralMeshComponent::CreateMeshSection()
So, it occurs on the call to CreateMeshSection() in the function I created… Why could this be?