Getting landscape informations using the pythin API

Hello everyone…
What i am trying to do is getting all information of a landscape ( width, height, num of components…), using the python API.

import unreal
l = unreal.EditorActorSubsystem().get_selected_level_actors()
all = unreal.EditorActorSubsystem().get_all_level_actors_components()
print(all)
#print(l)
#print(type(l[0]))
#print(l[0].is_editor_only_actor())
#print(unreal.Landscape().lod0_screen_size)
#print(unreal.LandscapeInfo(l[0]))
#landscape_info = l[0].get_landscape_info()
#landscape_info = l[0].create_landscape_info()

I was able to select the landscape in my level, but when trying to apply the methods available for the Landscape module, i always get " module Landscape has no property method_name", as well as there is a module named LandscapeInfo but it has no property or methods to use (unreal.LandscapeInfo — Unreal Python 5.0 (Experimental) documentation).
So how can i get these information or components using the API, or even from cpp code. My goal is to use the script to make custom components because i want to train a machine learning model using that data.
I hope i clarified my issue here, and to sum up, the python API for landscape module is not returning any useful data to use.

I’m having the same issue… did you find a solution?

Regards

Roberto

Hi,
Yeah but i did use the CPP API, and not the python API.
If you’re intrested i can show you the code.

yes please!!

Sorry for the late reply.
Here is a snippet of the code you can use to handle landscapes in cpp:

Includes:
#include <Runtime/Landscape/Classes/Landscape.h>
//#include <Runtime/Landscape/Classes/LandscapeProxy.h>
#include <Runtime/Landscape/Classes/LandscapeInfo.h>
#include <Runtime/Landscape/Classes/landscapeComponent.h>
landactor = {};//holder of the landscape actor. In .h it is defined as: TArray<AActor*> landactor;

	UGameplayStatics::GetAllActorsOfClass(GetWorld(), AActor::StaticClass(), landactor);// get the landscape actor fron world and store it in a variable.
	
	for (AActor* actor : landactor) {
		//Get the landscape 
		ALandscape* land = Cast<ALandscape>(actor); // Making sure we are handling a lanscape actor.

		if (land) {
			// This will give the x,y,z of the landscape in the world.
			FTransform actorLandscapePosition = land->LandscapeActorToWorld();
			//FBox landbox = land->GetComponentsBoundingBox();

			auto comp = land->LandscapeComponents;// get components of the landscape
			if (comp.Num() > 0) {
				
				//ULandscapeInfo* landInfo = land->GetLandscapeInfo(); // not really useful
				//UE_LOG(LogTemp, Display, TEXT("the actor is %d"), comp.Num());// print the number of components
				int componentnum = 0;//for iteration
				for (auto component : comp) {
					//Loop through each component

					//if (component.IsA(ULandscapeComponent::StaticClass())) {
					ULandscapeComponent* LandComponent = Cast< ULandscapeComponent>(component); // I just make a lot of test the the code won't crash 
					//UE_LOG(LogTemp, Display, TEXT("the actor is %s"), *LandComponent->GetComponentLocation().ToString());
					if (LandComponent) {
						//Getting the center of the component x,y,z
						FBoxSphereBounds Bounds = LandComponent->CalcBounds(FTransform::Identity);
						FVector Center = Bounds.Origin;
						Center -= LandComponent->GetComponentLocation();
										
						UE_LOG(LogTemp, Warning, TEXT("Component center point: %s"), *Center.ToString());

									//this is to get the w/h of the component 
									int32 ComponentSizeQuads = LandComponent->ComponentSizeQuads;
									int32 ComponentWidth = ComponentSizeQuads + 1;
									int32 ComponentHeight = ComponentSizeQuads + 1;
									FVector componentLocation = LandComponent->GetComponentLocation();//get component location in world 

So here is a snippet of the code, i am just showing the classes and functions to be used and how we can use them. I hope this will get you going with handling landscapes in cpp code.
Enjoy coding.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.