Announcement

Collapse
No announcement yet.

Trying to load in a .umap with a UBT Program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Trying to load in a .umap with a UBT Program

    Hello,

    I should probably explain my use case a little bit:
    I am trying to make a custom exporter for exporting my levels physics geometry to be used in my custom sever implementation. I want to open up the MainWorld, obtain the WorldComposition data's TileList, and iterate through those ULevels to get actors and export physics geometry.

    I would like this to be a separate tool if possible, outside of the editor. A program that a user could run to generate new terrain geometry for the custom server implementation, and be run as a part of CI to generate world navigation data.
    Ive created a UBT Program based off of the "BlankProgram" project in the Programs folder, and finally managed to be able to resolve the path to my level file.


    Code:
    using UnrealBuildTool;
    using System.Collections.Generic;
    
    [SupportedPlatforms(UnrealPlatformClass.Desktop)]
    public class WorldExporterTarget : TargetRules
    {
    public WorldExporterTarget(TargetInfo Target) : base(Target)
    {
    Type = TargetType.Program;
    DefaultBuildSettings = BuildSettingsVersion.V2;
    
    LinkType = TargetLinkType.Monolithic;
    LaunchModuleName = "WorldExporter";
    
    // Lean and mean
    bBuildDeveloperTools = false;
    
    // Never use malloc profiling in Unreal Header Tool.  We set this because often UHT is compiled right before the engine
    // automatically by Unreal Build Tool, but if bUseMallocProfiler is defined, UHT can operate incorrectly.
    bUseMallocProfiler = false;
    
    // Editor-only data, however, is needed
    bBuildWithEditorOnlyData = true;
    
    // Currently this app is not linking against the engine, so we'll compile out references from Core to the rest of the engine
    bCompileAgainstEngine = false;
    bCompileAgainstCoreUObject = true;
    bCompileAgainstApplicationCore = false;
    
    // UnrealHeaderTool is a console application, not a Windows app (sets entry point to main(), instead of WinMain())
    bIsBuildingConsoleApplication = true;
    }
    }
    Code:
    using UnrealBuildTool;
    
    public class WorldExporter : ModuleRules
    {
    public WorldExporter(ReadOnlyTargetRules Target) : base(Target)
    {
    //PublicIncludePaths.Add(EngineDirectory + "/Source/Runtime/Launch/Public");
    
    //PrivateIncludePaths.Add(EngineDirectory + "/Source/Runtime/Launch/Private");      // For LaunchEngineLoop.cpp
    
    PrivateDependencyModuleNames.AddRange(new string[] {
    //"ApplicationCore",
    "Core",
    "CoreUObject",
    "Projects",
    //"Engine",
    });
    }
    }
    Code:
    #include "WorldExporter.h"
    
    #include "GenericPlatform/GenericPlatformMisc.h"
    #include "Launch/Public/RequiredProgramMainCPPInclude.h"
    #include "Misc/Paths.h"
    #include "UObject/UObjectGlobals.h"
    
    
    DEFINE_LOG_CATEGORY_STATIC(LogWorldExporter, Log, All);
    
    IMPLEMENT_APPLICATION(WorldExporter, "WorldExporter");
    
    const FString ProjectDir = "C:/Path/To/UE4/Project";
    const FString MainWorldPackagePath = ProjectDir / "/Content/MainWorld.umap";
    
    INT32_MAIN_INT32_ARGC_TCHAR_ARGV()
    {
    FGenericPlatformMisc::SetOverrideProjectDir(ProjectDir);
    
    GEngineLoop.PreInit(ArgC, ArgV);
    
    UE_LOG(LogWorldExporter, Display, TEXT("Main World: %s"), *MainWorldPackagePath);
    
    FString LongTempFname;
    if (FPackageName::TryConvertFilenameToLongPackageName(MainWorldPackagePath, LongTempFname))
    {
    UE_LOG(LogWorldExporter, Display, TEXT("Main World Package: %s"), *LongTempFname);
    UPackage* MainWorldPackage = LoadPackage(nullptr, *LongTempFname, ELoadFlags::LOAD_None);
    MainWorldPackage->SetPackageFlags(PKG_NewlyCreated);
    
    UE_LOG(LogWorldExporter, Display, TEXT("Package Size: %i"), MainWorldPackage->GetFileSize());
    }
    
    return 0;
    }
    This compiles fun, but at runtime when the PackageLoader tries to load in the .umap, I get a bunch of errors:
    Code:
    [2020.06.28-18.39.11:912][  0]LogWorldExporter: Display: Hello World
    [2020.06.28-18.39.11:912][  0]LogWorldExporter: Display: Main World: D:/Projects/kenos/ue4/Content/MainWorld.umap
    [2020.06.28-18.39.11:912][  0]LogWorldExporter: Display: Main World Package: /Game/MainWorld
    [2020.06.28-18.39.16:521][  0]LogLinker: Warning: Package D:/Projects/kenos/ue4/Content/MainWorld.umap was saved with a custom integration that is not present. Tag 23AFE18E4CE14E588D61C252B953BEB7  Version 11
    [2020.06.28-18.39.16:521][  0]LogLinker: Warning: Package D:/Projects/kenos/ue4/Content/MainWorld.umap was saved with a custom integration that is not present. Tag 430C4D197154497087699B69DF90B0E5  Version 14
    [2020.06.28-18.41.05:814][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.41.05:814][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.41.05:814][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.41.05:814][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.41.05:815][  0]LogLinker: Warning: Unable to load MainWorld_C with outer Package /Game/MainWorld because its class does not exist
    [2020.06.28-18.43.05:441][  0]LogLinker: Warning: Unable to load Default__MainWorld_C with outer Package /Game/MainWorld because its class does not exist
    [2020.06.28-18.43.05:441][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.05:441][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.05:442][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.05:442][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.05:442][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.05:442][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.05:442][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    
    ... more errors of the same
    
    [2020.06.28-18.43.09:563][  0]LogLinker: Warning: Unable to load BP_Sky_Sphere_C with outer Package /Engine/EngineSky/BP_Sky_Sphere because its class does not exist
    [2020.06.28-18.43.09:564][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.09:565][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.09:567][  0]LogLinker: Warning: Unable to load Default__BP_Sky_Sphere_C with outer Package /Engine/EngineSky/BP_Sky_Sphere because its class does not exist
    [2020.06.28-18.43.09:568][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.09:569][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.09:570][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.09:571][  0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.43.09:572][  0]LogLinker: Warning: Unable to load BP_Sky_Sphere with outer Package /Engine/EngineSky/BP_Sky_Sphere because its class does not exist
    
    ...
    Something tells me here that I need to be able to link in the Engine, but to do that I also have to bring in application core.

    Code:
    // Currently this app is not linking against the engine, so we'll compile out references from Core to the rest of the engine
    bCompileAgainstEngine = true;
    bCompileAgainstCoreUObject = true;
    bCompileAgainstApplicationCore = true;
    and in Build.cs
    Code:
    PrivateDependencyModuleNames.AddRange(new string[] {
    "ApplicationCore",
    "Core",
    "CoreUObject",
    "Projects",
    "Engine",
    });
    trying to build that leads to:

    Code:
    1>UnrealBuildTool : error : Unable to instantiate module 'UnrealEd': Unable to instantiate UnrealEd module for non-editor targets.
    1>                        (referenced via Target -> WorldExporter.Build.cs -> Engine.Build.cs -> UMG.Build.cs -> MovieSceneTracks.Build.cs -> BlueprintGraph.Build.cs -> KismetCompiler.Build.cs)
    Well, after that I tried to turn the project type to Editor, but there are compiler errors everywhere unfortunately.


    I don't know if I am approaching this in the right direction to begin with.

    I'm not sure how to proceed from here - Linking in the Editor as a monolithic build requires ~1100 files to compile, and turning it to default results in around ~2200, which I could deal with if I managed to get the c++ errors to work.

    I am trying to see if there is another project that manages to open up a UPackage and read in the ULevel scene, but I have had no luck thus far.

    Currently, Im trying to figure out what these paths are supposed to signify:
    Code:
    [2020.06.28-18.41.05:814][ 0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    [2020.06.28-18.41.05:814][ 0]LogUObjectGlobals: Warning: Failed to load '/Script/Engine': Can't find file.
    Thanks,
    MS
    Last edited by MDSRS; 06-28-2020, 05:46 PM. Reason: context
Working...
X