Can't assign the landscape LayerInfo object to a landscape


I’ve been developing an automated system that requires me to generate the LayerInfo objects of a given Landscape, so far I’ve been able to generate the required LayerInfo object’s, but I wasn’t able to assign them. Or to be more precise when I try to assign the necessary layers in the ULandscapeInfo property they appear in the editor but are not assigned, unless I save them and restart the engine, they also appear weird in the editor, as you can see in the image. I think it’s a similar problem to the one in this thread. The code bellow it’s responsible for assignig the LayerInfo:

	// This method creates a
	// new layer info objectB
	UWorld * currentWorld = GetWorld();
	ULevel * level = currentWorld->GetLevel(0); // TODO : just for debuging 
	ULandscapeLayerInfoObject* layerInfo = Landscape->CreateLayerInfo(*(layerName), level);
	bool isDirty = layerInfo->MarkPackageDirty();

	// Get a reference for the landscape Info
	ULandscapeInfo* landscapeInfo = Landscape->GetLandscapeInfo();
	FLandscapeInfoLayerSettings* layerSettings = &landscapeInfo->Layers[1];

	landscapeInfo->Layers[0] = FLandscapeInfoLayerSettings(layerInfo, Landscape);
	UEditorAssetLibrary::SaveAsset(assetName, false);
	// Assign the respective values
	if (!layerSettings->LayerInfoObj)
		layerSettings->Owner = Landscape;
		layerSettings->LayerInfoObj = layerInfo;
		layerSettings->bValid = true;