Stream an asset from the internet
Hi, I would like to know if it is possible to stream an asset from the internet for a mobile application made in unreal, where I could have an option to download new products to view in 3D inside the app (game).
asked Oct 06 '14 at 05:16 PM in Blueprint Scripting
Yes there is. But it is a bit harder then in Unity (at the moment at-least). The solution has two steps, one is preparing the assets in a bundle and the other is serving the asset and streaming it.
1) Bundling your assets
The first step is to bundle all your assets (BPs are yet another question) into a so called PAK file. Unreal comes with a tool to bundle uassets and umaps into PAK files called UnrealPak. I have posted more info about UnrealPak in the following thread: https://answers.unrealengine.com/questions/105923/downloadable-content-1.html
2) Serving your bundles
Again we have to use a tool called the UnrealFileServer, its a static file server that handles the Unreal network protocol and is able to stream PAK files. You can then create a NetworkPlatformFile that is able to open remote files and stream the content of the PAK files. This even works when you stream a texture where texture streaming is applied.
There is quite a bit of work in this part part you should be able to start with this engine module: NetworkFileSystem and its FNetworkFileServer class.
One side note that took me days to discover is that once you are able to stream a PAK file you have to mount that file within the realm of Unreal's file system (all the /Game/ /Engine/ paths). The tricky thing is that to be able to load and mount a PAK file from the network asynchronously is that you have to mount it in the engine path starting with /Engine/ instead of the game path /Game/. What I do is just adding a path that will be unique for me and my game like /Engine/Content/MyAwesomeGame/ to avoid collisions with existing engine assets.
To initialize the network you require to create several platform files. A platform file is a file manager providing you with the ability to load certain files.
You require to hold a reference to the current one you will be using and to the others so you can switch between them (for local and remote loading), you might end with something like this in your helper object.
It could be that you need to create forward declarations for the above types
Don't forget to initialize the NetPlatform and the PakPlatform.
So we have now our files ready and can start to initialize the network one using a host string (host:port)
The following presents the structure of how to stream using the NetPlatform. You will also need a refernce to a FStreamableManager, I recomend you to add one into your GameSingleton class (https://wiki.unrealengine.com/Global_Data_Access,_Data_Storage_Class_Accessible_From_Any_CPP_or_BP_Class_During_Runtime#The_CPP_Base_Class).
The next part would be performing the local loading part, which si very similar to the remote one. Just initialize the PakPlatform to be using the saved PlatformFile from the initialization phase.
You must also adapt your build.cs file to include the following.
When using 4.5 you must also change the buid.cs file of an engine module (I'm preparing a pull request for this). The StreamingFile modules needs to add the Socket module as its public dependencies. You could also try to adding the Socketsn dependency to your public dependencies instead the engine modules one. But just in case:
I know this is a loooooot of stuff :D But I hope you will be able to start your work streaming pak files from the net! This will be all included in a plugin I'm preparing with Ruben (the one who posted earlier :D)
EDIT: This is a sample plugin featuring the above code: https://github.com/moritz-wundke/AsyncPackageStreamer
Follow this question
Once you sign in you will be able to subscribe for any updates here