Problem with creating a StreamingLevel (C++)

Hi all
I am new to the forum and I am struggling with understanding level instancing. (in runtime)
I have a few questions:
How to create a new level integrated with WorldPartition streaming system?
How to bind actors to it?
Does it need to be saved when a player gets further?

Minimal reproduceable example:
Create blank c++ project
Name it “Test1”
Quality preset scalable
Target platform desktop
Disable starter content

World Settings → World Partition Setup → Runtime Settings → Grids[0] → Cell Size = 6400, Loading Range = 12800

Delete all the landscape
Create a cube at the origin

Save the level as “LevelMain” in “Content” directory

Create new level “LevelOne” in “Content” directory
Create public Actor class ActorForNewLevel:
Just add one public int field to .h file:
ActorForNewLevel.h :

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ActorForNewLevel.generated.h"

UCLASS()
class TEST1_API AActorForNewLevel : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actors properties
	AActorForNewLevel();
	UPROPERTY(EditAnywhere)
	int TestPublicIntField;

	USceneComponent* rootSceneComponent;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

};

Initialize it with 0 :
ActorForNewLevel.cpp :

// Fill out your copyright notice in the Description page of Project Settings.


#include "ActorForNewLevel.h"

// Sets default values
AActorForNewLevel::AActorForNewLevel()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you dont need it.
	PrimaryActorTick.bCanEverTick = true;
	TestPublicIntField = 0;
	rootSceneComponent = CreateDefaultSubobject<USceneComponent>(FName(TEXT("DefaultSceneComponent")));
	SetRootComponent(rootSceneComponent);
}

// Called when the game starts or when spawned
void AActorForNewLevel::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AActorForNewLevel::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

Create a component NewLevelSpawner:
NewLevelSpawner.h :

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "NewLevelSpawner.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class TEST1_API UNewLevelSpawner : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this components properties
	UNewLevelSpawner();
	UPROPERTY(EditAnywhere)
	bool created;

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

		
};

Add level instancing code in .cpp BeginPlay:
NewLevelSpawner.cpp :



#include "NewLevelSpawner.h"
#include "Engine/LevelStreamingDynamic.h"

// Sets default values for this components properties
UNewLevelSpawner::UNewLevelSpawner()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you dont need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...

	created = false;
}


// Called when the game starts
void UNewLevelSpawner::BeginPlay()
{
	Super::BeginPlay();

	if (created) return;
	created = true;

	// Create a level
	bool success;
	FString name = TEXT("LevelOneInstance");
	ULevelStreamingDynamic* level = ULevelStreamingDynamic::LoadLevelInstance(GetWorld(), "LevelOne", FVector(6400, 0, 0), FRotator::ZeroRotator, success, name);
	if (!success) {
		GEngine->AddOnScreenDebugMessage(-1, 60, FColor::Red, TEXT("Cannot load level"));
	}
	else {
		created = true;
		GetWorld()->AddStreamingLevel(level);
		GetWorld()->FlushLevelStreaming();
		GetWorld()->UpdateLevelStreaming();
	}
	
}


// Called every frame
void UNewLevelSpawner::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// ...
}

Compile code

Add one ActorForNewLevel to LevelOne
Set it’s position to origin
Save LevelOne

Add NewLevelSpawner component to the cube in LevelMain
Save LevelMain

Set network mode to standalone

Start the simulation
You can see LevelOneInstance and ActorForNewLevel are created
Set TestPublicIntField of that actor to 1 using editor
If you get further from the cube in LevelMain, it despawns properly.

Problem 1: the actor does not despawn no matter how far away you get from it. (go to scene view for being faster)
Solution 1:

  1. Convert LevelOne to partition system and set partition properties same as for LevelMain
  2. (why??) add a cube as a component for ActorForNewLevel
    Now the level can unload and load.

Problem 2:
Set TestPublicIntField to 1 in runtime from the editor
Go furrther, then closer. Repeat loading-unloading for several seconds.
Then for a certain attempt of loading it shows that TestPublicIntField=0 and completely stops to load from any saved profile. How to load and unload levels created in runtime properly?