I need to read the heights of a Landscape at startup. When I create a level using the Basic map template and create a Landscape I can read various things about the Landscape through the LandscapeComponents array in the Landscape. When I create the level using any of the Open World map templates the Landscape doesn’t get any Landscape Components, not even after a few seconds of play time so it doesn’t seem to be a streaming delay problem.
How do I read get the Landscape Components in an Open World / World Partition level?
// What I originally had. Is now an empty array.
Landscape->LandscapeComponents;
ULandscapeInfo* LandscapeInfo = Landscape->GetLandscapeInfo();
// Use the ForAllLandscapeComponents function.
LandscapeInfo->ForAllLandscapeComponents(
[&NumLandscapeComponents, &Landscape](ULandscapeComponent*)
{
// This lambda is executed 0 times.
});
// Get Landscape Components from the Landscape's Streaming Proxies.
// This array is empty.
for (ALandscapeStreamingProxy* StreamingProxy : LandscapeInfo->Proxies)
{
// What I would like to access, but this lambda also executes 0 times.
Proxy->LandscapeComponents;
}
// Another type of Proxy.
LandscapeInfo->ForAllLandscapeProxies(
[&NumLandscapeComponents](ALandscapeProxy* Proxy)
{
// What I would like to access, but this lambda also executes 0 times.
Proxy->LandscapeComponents;
});
// Use the Collision Components instead.
Landscape.RecreateCollisionComponents(); // Try to force creation. Makes no difference.
for (ULandscapeHeightfieldCollisionComponent* CollisionComponent : Landscape.CollisionComponents)
{
// Loop body executed 0 times.
}
// Try to use the global getter, but this gives me a liker error.
const TArray<ALandscapeProxy*>& Proxies = ALandscapeProxy::GetLandscapeProxies();
for (ALandscapeProxy* Proxy : Proxies)
{
}
What worked for me to get those components is to delete the default landscape. and create a new one. could’ve been version upgrade from 5.3.0 to 5.3.1 not sure. but now I have the components.