I’ve managed to dynamically load a pak with FCoreDelegates::OnMountPak.Execute() but it fails when I try and load a map from it.
I’ve tried ServerTravel and UGameplayStatics::OpenLevel - OpenLevel returns an error that the map cannot be found - the map is specified as the name returned when I look at it’s reference from the editor (e.g. /Game/MyMap.MyMap).
Has anyone found any useful documentation on doing this, or have any clues as to what could be going wrong?
After seeing an example where an asset was being loaded with a “StaticMesh’’” wrapper I found that “Copy Reference to clipboard” provides something similar to World’/Game/MyMap.MyMap’. I plugged that into my code but the results are the same - OpenLevel has no return code so can’t tell if it has failed apart from the fact that UE is still displaying the old levels map. Anyone?
Saving a map to the base project and loading that with UGameplayStatics::OpenLevel works fine.
Either “World’/Game/MyMap.MyMap’” or “MyMap” appear to work.
When attempting to load the dynamically loaded pak file it looks like it’s trying to load - it creates a new UWorld and a new GameMode - calls the GameMode::InitGame method. Querying the new World returns the base projects Map name though and the old map is still displaying. The log file tells me that it has loaded, no error entries.
I had my Oculus Rift plugged into the HDMI but not USB, I unplugged the HDMI and now I am getting error messages about not finding the map in the log file - most strange, but also much more helpful - Still, I’ve tried all incantations of the map name and it still does not find it.
There’s a function you can call to mount a pak to a root path (/game, /engine etc). Away from computer at the moment but I found it when searching the engine code for an error about root names.
The comments implied that use of this would allow you to override existing asset access with new assets. As soon as I called it the engine mounted assets in my pak and I’ve been able to load utextures and usoundcues using short paths - including in standalone builds.
Might not help you but here’s the code I’ve got to mount pak files (not tested umaps yet). The first few lines are setting the mount point to the pak file location so files can be pathed relative to that - MakeStandardFilename is very important in the approach I take - the internal pak file directory structure is quite sensitive to paths.
RegisterMountPoint makes my files accessible using the short file names. In this case a filename of a/b/c.uasset within the pak would become /dlc/a/b/c
The output after has proven useful while working through my own pak file woes, so I’ve included it here.
StandardFilename = FPaths::GetPath(StandardFilename);
if (!mp_DLCPakFiles->Mount(*rPakFileName, 0, *StandardFilename))//DLCPakMountPoint))
Errorf(_T("DLC - Unable to mount pak file '%s' to '%s'"), *rPakFileName, *StandardFilename);
struct Dump : public IPlatformFile::FDirectoryVisitor
virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory)
Outputf(_T("Directory: %s"), FilenameOrDirectory);
Outputf(_T("File: %s"), FilenameOrDirectory);
The FPackageName::RegisterMountPoint() was what I was missing.
So far adding that to my code I can now load maps ok but the assets contained in the maps… not so much… will keep working on that.
The Mount point from what I can tell is the original file location of the pak contents rather than the location of the created pak file - this may be because I’m loading a pak with FCoreDelegates::OnMountPak.Execute(). Is your mp_DLCPakFiles a folder on disk?
I also noted that if I have a uasset file located on disk at the location I add for the MountPoint, it will load that asset before checking the mounted pak file - that ones a bit of a trap…
Think of it as an extension to the file system - I load the map after setting a mount point like this:
FPackageName::RegisterMountPoint("/Game/","path to my map");
The “path to my map” is the physical path on disk to the map file (excluding the map name) - it can be embedded in a pak file or just be a umap file on disk. The “/Game/” is the root path you want to map it to - “/Game/” is just where I have things, you can place them in other folders within that.
Do you mean the assets within the pak file - are you trying to load those? If so, the path to them should be relative to the mount point you set. If you used “/Game/” which is the root you would specify “Meshes/MyMesh.uasset” for a mesh that is located in a “Meshes” folder.
Hi TestyRabbit. Yeah I did get it working - I’ve attached a link to the sourcecode I used (there are a lot of commented out bits from various attempts but it successfully loads maps and assets… The link for the cpp file is: http://r4nc1d.com/files/deepHelpers.cpp - the LoadMap() function is the one with the important bits in it, I call it from my app with LoadMap(“Footprints”,"/Game/",“c:\Program Files (x86)\Slidescape\Content\Scenes\Deep\Footprints”) The assets all have to be cooked first, and then packaged with the Unreal Package program UnrealPak.exe…
Holy cow you’re a lifesaver. I’m working on some other stuff but I’ll have to take a look at this tomorrow. Thank you, if I have questions I may reach out if that’s alright. this has been a real big ■■■■■ haha.
When it comes to mounting, did you use the FCoreDelegates approach? Because my issue with that approach is that after I mount the pak with that, it is unable to resolve the map name. If I use the PakFile approach I’m able to find the map but all of the assets are gone.
This is the path that my map is at in the pakfile: USETHIS/Content/test.umap (The visitor prints this out). Does that mean that I would call it like this? LoadMap("test", "/Game/", "D:\\UE4\\4.17\\USETHIS\\Content");, I’m trying to load the map into a project called “PakTest” located at “D:\UE4\4.17\PakTest\”
Yeah that’s the bits that are needed - the rest is experiments, I did this a number of years ago so it’s a bit foggy but I do remember having the same issue with the FCoreDelegates approach even though there were a number of people recommending it. This was the only way I could get the maps and all assets to load.
I also remember trying to use a separate folder like “USETHIS” but that didn’t work for me either so I stuck with “/Game/” and made sure all assets were within that folder (or subfolder).
If your map is called “test” and the folder it resides in is “D:\UE4\4.17” those should be the parameters - so it would be LoadMap(“test”,"/Game/",“D:\UE4\4.17”);