Sliced (Other half) Procedural Mesh is not where editor says it is!

I am trying to animate an avatar to grasp a slice of bread, but the real location of the slice (the procedural mesh component) is not the location the editor says it has. So I am not able to drive the avatar’s hand to the right spot. The location is not even equal or related to the parent actor location.

This is the location of the first slice (*Component_0 in the very left):

Editor’s location of slice

[That location marked in the level] (Universitaet Bremen - Seafile “Point location in the level”)

As you can see the mark is not where the first slice actually is (as seen in the level) even though both have the same location (As seen in the details section).

Am I missing something?, anyone have seen this before?

I can confirm now that new slices are getting the parent’s location. They differ from parent’s location because they move and rotate after cutting, but their origin is as if the bread still complete. Does somebody know how to fix origin during play?

OK, given that I was already converting the new slices from procedural mesh (PM) to static meshes, I am making sure that during this process I create the new static mesh with the right origin.

So when copying every vertex from the PM and every vertex data from the convex elements of the PM’s AggGeom (collision data), I add a correction offset to them (based on PM’s bounds origin) , then I set the location of entire component back to the right place.

	// Get origin location of AABB. This would be the offset
	FVector Origin = ProceduralMeshComponent->Bounds.Origin;
	FVector OriginLocal = ProceduralMeshComponent->GetComponentTransform().InverseTransformPosition(Origin);

	const int32 NumSections = ProceduralMeshComponent->GetNumSections();
	int32 VertexBase = 0;
	for (int32 SectionIdx = 0; SectionIdx < NumSections; SectionIdx++)
	{
		FProcMeshSection* ProcSection = ProceduralMeshComponent->GetProcMeshSection(SectionIdx);

		// Copy verts
		for (FProcMeshVertex& Vert : ProcSection->ProcVertexBuffer)
		{
			// Subtract offset to vertex
			if (centerOrigin) {
				Vert.Position -= OriginLocal;
			}
			RawMesh.VertexPositions.Add(Vert.Position);
		}
		//...
	}
	//...
		FKAggregateGeom CollGeom = ProceduralMeshComponent->GetBodySetup()->AggGeom;
		if (centerOrigin) {
			int32 totalElems = CollGeom.ConvexElems.Num();
			for (int32 idx = 0; idx < totalElems; idx++) {

				TArray<FVector> *vertexs = &CollGeom.ConvexElems[idx].VertexData;
				int32 totalVertexs = vertexs->Num();
				// Subtract offset to collision vertex
				for (int32 v_idx = 0; v_idx < totalVertexs; v_idx++) {
					(*vertexs)[v_idx] -= OriginLocal;
				}
			}
		}
	//...

when we subtract the bound’s origin (which is at an offset from component’s origin) we move everything (mesh and collision) to the component’s origin. But the world location of the component is supposed to be where the bound’s origin was, so:

	if (centerOrigin) {
		NewStaticMeshComponent->SetWorldLocation(ProceduralMeshComponent->Bounds.Origin);
	}
1 Like