I found a workaround.
If the mesh is too complex and has way too many UV shells on its lightmap, then UE4 will give you a warning about overlapping UVs. What I do in this case is separate the mesh into parts, make UV lightmaps for each part, and assemble the parts inside a blueprint to make the object whole again.
On a screenshot in my original post I tried to make a big section of rail tracks as a single mesh. The idea was to combine spline meshes into a single mesh to reduce draw calls, and then generate lightmap channel for it in UE4. Didn’t work so well, as you can see - the amount of UV shells on the lightmap channel was too high. I then split the tracks into several sections and generated lightmap UVs for each of the sections, and the problem was gone.
