I want to add a new UWorld instance to engine in my pluging.
UWorld * World = UWorld::CreateWorld(EWorldType::Editor,true);
It work when StartupModule. And I have a SceneOutliner.
UWorld * World = UWorld::CreateWorld(EWorldType::Editor,true);
FActorSpawnParameters Parameters{};
Parameters.Name = "hehe";
World->SpawnActor(AStaticMeshActor::StaticClass(),nullptr,nullptr,Parameters);
auto Res = GEngine->GetWorldContexts();
UE_LOG(LogTemp,Warning,TEXT("Number: %d"),Res.Num());
// GWorld = World;
SceneOutliner::FInitializationOptions InitOptions;
InitOptions.SpecifiedWorldToDisplay = World;
check(World); //ok not null
FSceneOutlinerModule& SceneOutlinerModule = FModuleManager::Get().LoadModuleChecked<FSceneOutlinerModule>("SceneOutliner");
Outliner = SceneOutlinerModule.CreateSceneOutliner(InitOptions,FOnActorPicked::CreateRaw(this,&FHotEditUiModule::HandleActorPicked));
but the log Numer of Res is 1. It’s PIE of default.
Run
The word of SceneOutliner not is my new world. It’s PIE also.
I See the source code of SSceneOutliner. The problem from here
// check if the user-chosen world is valid and in the editor contexts
if(UWorld* UserChosenWorld = SharedData->UserChosenWorld.Get()) //not have my word
{
for (const FWorldContext& Context : GEngine->GetWorldContexts())
{
if(UserChosenWorld == Context.World())
{
SharedData->RepresentingWorld = UserChosenWorld;
break;
}
}
}
// when I add this line. the outliner of my world can be render right. not default pie
// SharedData->RepresentingWorld = SharedData->UserChosenWorld.Get();
how to add world instance to contexts of GEngine->GetWorldContexts()