When creating a new mesh section in the ProceduralMeshComponent, all existing sections with higher index are removed

Branch: Binary build from the Unreal Launcher.

Build version: Version: 4.8.1-2591939

Description: When calling the CreateMeshSection function (with the argument “SectionIndex”) in the new ProceduralMeshComponent, the section array is resized to “SectionIndex+1”. This has the effect, that all existing sections with higher index than “SectionIndex” are deleted. I guess that is not intended.

Repro Steps

Action 1: Create new ProceduralMeshComponent

Action 2: Create mesh section with index 1, then create mesh section with index 2

Action 3: Update/create mesh section with index 1 (this will delete section 2)

Does this occur in a clean, blank project with no additional content or is this limited to a specific project? How are you setting the mesh indexes? Can you show me a screenshot of your blueprint setup?

This occurs in a clean project. I set up the mesh just using C++ with the CreateMeshSection(…) function. I call this function every second (using Tick(…)) with a different section index in order to update the corresponding mesh part.

If I have three mesh sections:
1st sec → update section 0,
2nd sec → update section 1,
3rd sec → update section 2,
4th sec → update section 0 (This will delete sections 1 and 2)

I compiled the engine from source now and added a range check to CreateMeshSection. Before resizing the ProcMeshSections array, I just check if the section index is bigger than the current array size. This solves the problem.

Hey -

Could you elaborate on your repro steps? After creating a new class based on ProceduralMeshComponent how exactly are you creating the mesh sections? Can you post the code that you used with your repro steps?

Hey -

We’ve not heard from you in a couple days. I will be marking this post as resolved for tracking purposes, however if you’re still having any issues with ProceduralMeshComponent please feel free to respond with the information requested and we will continue to investigate.

Cheers

Hi,
sorry I dont have access to the code I used at the moment, but I think you can just create 5 sections with just one triangle, where the triangle is shifted in each section. Then update the first section again in the last step. Only the first section will remain.

Create a new class based on AActor and add a procedural mesh component as a member variable. After creating this mesh component:

for (int i=0; i<5; i++) {
    TArray<FVector> vertices;
    TArray<int32> faces;
    vertices.Add(FVector(0,0, i * 100));
    vertices.Add(FVector(100,0, i * 100));
    vertices.Add(FVector(100,100, i * 100));
    faces.Add(0);
    faces.Add(1);
    faces.Add(2);
    ProcMeshComponent->CreateMeshSection(i, vertices, faces, TArray<FVector>(), TArray<FVector2D>(),  TArray<FColor>(), TArray<FProcMeshTangent>(), false);
}

TArray<FVector> vertices;
TArray<int32> faces;
vertices.Add(FVector(0,0, 0));
vertices.Add(FVector(100,0, 0));
vertices.Add(FVector(100,100, 0));
faces.Add(0);
faces.Add(1);
faces.Add(2);
ProcMeshComponent->CreateMeshSection(0, vertices, faces, TArray<FVector>(), TArray<FVector2D>(),  TArray<FColor>(), TArray<FProcMeshTangent>(), false);

I can verify if the problem also happens with this code tomorrow.

Edit: Yes, it happes with this example as well

What function are you adding the for() loop to? Is this being done inside the constructor or begin play or another function? Are you using the for() loop as well as repeating the code outside the loop? Let me know if you’re also able to reproduce this in a new project.

Hey -

Where is this for loop being added? Is this going inside the constructor of the actor or in another function? Are you using both the for loop as well as the lines posted after (which appear to be the same code without the loop)?

Hi,
yes I use both the loop and the lines after it. As I said, I update the first section again at the end, that is why I have the same code again after the loop. You can put this code anywhere, I have it in BeginPlay.

Hey -

The issue seems to be that the scope of the arrays is not being considered. When the loop is entered the first time it will create the vertices and faces arrays. Because they only exist inside the loop, each iteration of the loop will recreate both arrays. The arrays are again recreated once the loop exits. Moving the first two lines of the loop to before the loop is called and removing the first two lines after the loop completely should solve the problem.

Cheers

Hi,
isn’t the content of these arrays copied in CreateMeshSection? And why is it working when I dont add the lines after the loop? In this case sections 0-4 are rendered correctly.
Anyway as I already wrote above I fixed the problem for me by adding a range check to the CreateMeshSection code (before resizing the sections array). I just wrote it here that you are aware of that, I will not investigate this problem further.
Cheers,