MCPcopy Create free account
hub / github.com/URLab-Sim/UnrealRoboticsLab / CreateLevelSync

Function CreateLevelSync

Source/URLabEditor/Private/MjLevelOps.cpp:161–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159} // namespace
160
161bool CreateLevelSync(const FString& NameOrPath, bool bForceOverwrite,
162 FString& OutLevelPath, FString& OutError)
163{
164 ULevelEditorSubsystem* Sub = GetLevelSub();
165 if (!Sub)
166 {
167 OutError = TEXT("LevelEditorSubsystem unavailable");
168 return false;
169 }
170
171 OutLevelPath = ResolveLevelPath(NameOrPath);
172
173 if (bForceOverwrite)
174 {
175 const FString AssetName = FPaths::GetBaseFilename(OutLevelPath);
176 const FString ObjectPath = FString::Printf(TEXT("%s.%s"), *OutLevelPath, *AssetName);
177 bool bWasFound = false;
178 FString DestroyErr;
179 if (!DestroyAssetSync(ObjectPath, bWasFound, DestroyErr))
180 {
181 OutError = FString::Printf(
182 TEXT("force_overwrite failed to clear %s: %s"),
183 *ObjectPath, *DestroyErr);
184 return false;
185 }
186 }
187
188 if (!Sub->NewLevel(OutLevelPath))
189 {
190 OutError = FString::Printf(
191 TEXT("NewLevel failed for %s (already exists?)"), *OutLevelPath);
192 return false;
193 }
194
195 // Override the world's default game mode to AGameModeBase so PIE
196 // doesn't pull in the project-default game mode (and its transitive
197 // BP references). Without this, projects with broken third-party
198 // content -- e.g. Marketplace Mannequin AnimBPs that fail to
199 // compile -- pop a "Blueprint Compilation Errors" modal during
200 // PIE start, which blocks the game thread and times out begin_pie
201 // at 30s. AGameModeBase is the minimal default and has no BP refs.
202 if (UWorld* World = GEditor ? GEditor->GetEditorWorldContext().World() : nullptr)
203 {
204 if (AWorldSettings* WS = World->GetWorldSettings())
205 {
206 WS->DefaultGameMode = AGameModeBase::StaticClass();
207 WS->MarkPackageDirty();
208 }
209 }
210
211 if (!Sub->SaveCurrentLevel())
212 {
213 OutError = TEXT("NewLevel succeeded but SaveCurrentLevel failed");
214 return false;
215 }
216 return true;
217}
218

Callers 2

HandleCreateLevelFunction · 0.85
RunTestMethod · 0.85

Calls 3

GetLevelSubFunction · 0.85
ResolveLevelPathFunction · 0.85
DestroyAssetSyncFunction · 0.85

Tested by 1

RunTestMethod · 0.68