How to load heighmap in C++

Since nobody ever helps here with this question, I’l do. I managed to make procedural landscape in multiple ways (albeit took me a month of looking throuhg plugins, experimenting, even trying to make my own landscape solution)
.

  1. load from texture using: LandscapeTest->LandscapeComponents[i]->SetHeightmap(HeightMap);

  2. load from rendertexture using:
    ||TArray SurfData;|
    |—|—|
    ||auto RenderTarget = RTHeightMap->GameThread_GetRenderTargetResource();|
    ||RenderTarget->ReadPixels(SurfData);|

  3. just writing heights to FColor:

    for (int x = 0; x < 256; x++)
    {
    for (int y = 0; y < 256; y++)
    {
    uint8 height = x;
    SurfData.Add(FColor(height, height, height, height));
    }
    }

Additionally need to call some function to trigger the redraw and recreate collisions:

for (int i = 0; i < LandscapeTest->LandscapeComponents.Num(); i++)
{
	LandscapeTest->LandscapeComponents[i]->MarkRenderStateDirty();

	LandscapeTest->LandscapeComponents[i]->InitHeightmapData(SurfData, true);

	// NOTE: crash if edit layers is on.
	// NOTE: crash cuz of no mips.
	// NOTE: srgb collision offset?
	//LandscapeTest->LandscapeComponents[i]->SetHeightmap(HeightMap);
	LandscapeTest->LandscapeComponents[i]->RequestHeightmapUpdate(true, true);

	LandscapeTest->LandscapeComponents[i]->UpdateCachedBounds(true);
	LandscapeTest->LandscapeComponents[i]->PostLoad();
}

//for (int i = 0; i < LandscapeTest->CollisionComponents.Num(); i++)
//	LandscapeTest->CollisionComponents[i]->RecreateCollision();

LandscapeTest->RecreateCollisionComponents();