ULevel* CreateNewLevel( UWorld* InWorld, bool bMoveSelectedActorsIntoNewLevel, UClass* LevelStreamingClass, const FString& DefaultFilename ) { // Editor modes cannot be active when any level saving occurs. GEditorModeTools().ActivateMode( FBuiltinEditorModes::EM_Default ); // Create a new world - so we can 'borrow' its level UWorld* NewGWorld = UWorld::CreateWorld(EWorldType::None, false ); check(NewGWorld); // Save the new world to disk. const bool bNewWorldSaved = FEditorFileUtils::SaveLevel( NewGWorld->PersistentLevel, DefaultFilename ); FString NewPackageName; if ( bNewWorldSaved ) { NewPackageName = NewGWorld->GetOutermost()->GetName(); } // Destroy the new world we created and collect the garbage NewGWorld->DestroyWorld( false ); CollectGarbage( GARBAGE_COLLECTION_KEEPFLAGS ); // If the new world was saved successfully, import it as a streaming level. ULevel* NewLevel = NULL; if ( bNewWorldSaved ) { NewLevel = AddLevelToWorld( InWorld, *NewPackageName, LevelStreamingClass ); // If we are moving the selected actors to the new level move them now if ( bMoveSelectedActorsIntoNewLevel ) { GEditor->MoveSelectedActorsToLevel( NewLevel ); } // Finally make the new level the current one InWorld->SetCurrentLevel( NewLevel ); } // Broadcast the levels have changed (new style) InWorld->BroadcastLevelsChanged(); return NewLevel; }
void NUTNet::CleanupUnitTestWorlds() { for (auto It=PendingUnitWorldCleanup.CreateIterator(); It; ++It) { UWorld* CurWorld = *It; // Remove the tick-hook, for this world int32 TickHookIdx = ActiveTickHooks.IndexOfByPredicate( [&CurWorld](const FWorldTickHook* CurTickHook) { return CurTickHook != NULL && CurTickHook->AttachedWorld == CurWorld; }); if (TickHookIdx != INDEX_NONE) { ActiveTickHooks.RemoveAt(TickHookIdx); } GEngine->DestroyWorldContext(CurWorld); CurWorld->DestroyWorld(false); } PendingUnitWorldCleanup.Empty(); // Immediately garbage collect remaining objects, to finish net driver cleanup CollectGarbage(GARBAGE_COLLECTION_KEEPFLAGS, true); }
bool RunTest(const FString& Parameters) override { // find the matching test TestFunc TestFunction = nullptr; for (int32 i = 0; i < TestFunctionNames.Num(); ++i) { if (TestFunctionNames[i] == Parameters) { TestFunction = TestFunctions[i]; break; } } if (TestFunction == nullptr) { return false; } // get the current curve and data table (to restore later) UCurveTable *CurveTable = IGameplayAbilitiesModule::Get().GetAbilitySystemGlobals()->GetGlobalCurveTable(); UDataTable *DataTable = IGameplayAbilitiesModule::Get().GetAbilitySystemGlobals()->GetGlobalAttributeMetaDataTable(); // setup required GameplayTags UDataTable* TagTable = CreateGameplayDataTable(); IGameplayTagsModule::Get().GetGameplayTagsManager().PopulateTreeFromDataTable(TagTable); UWorld *World = UWorld::CreateWorld(EWorldType::Game, false); FWorldContext &WorldContext = GEngine->CreateNewWorldContext(EWorldType::Game); WorldContext.SetCurrentWorld(World); FURL URL; World->InitializeActorsForPlay(URL); World->BeginPlay(); // run the matching test uint64 InitialFrameCounter = GFrameCounter; { GameplayEffectsTestSuite Tester(World, this); (Tester.*TestFunction)(); } GFrameCounter = InitialFrameCounter; GEngine->DestroyWorldContext(World); World->DestroyWorld(false); IGameplayAbilitiesModule::Get().GetAbilitySystemGlobals()->AutomationTestOnly_SetGlobalCurveTable(CurveTable); IGameplayAbilitiesModule::Get().GetAbilitySystemGlobals()->AutomationTestOnly_SetGlobalAttributeDataTable(DataTable); return true; }
void RunWorld(const FURL& URL, FJavascriptFunction Function) { UWorld *World = UWorld::CreateWorld(EWorldType::Game, false); FWorldContext &WorldContext = GEngine->CreateNewWorldContext(EWorldType::Game); WorldContext.SetCurrentWorld(World); World->InitializeActorsForPlay(URL); World->BeginPlay(); // run the matching test uint64 InitialFrameCounter = GFrameCounter; { FJavascriptRunWorldParameters Params; Params.World = World; Function.Execute(FJavascriptRunWorldParameters::StaticStruct(), &Params); } GFrameCounter = InitialFrameCounter; GEngine->DestroyWorldContext(World); World->DestroyWorld(false); }