Download missing assets from the internet

Hello, I’m trying to download a .pak/.zip file from a server and extract the contents into a directory. I’ve looked up on streaming/downloading assets from the server but the solutions seem a little complex to understand or set up.

Please assist.

This is what I did to download and save the asset. But the statement that is supposed to load the asset does not seem to work:

Added “Http” to list of dependency modules in project’s Build.cs

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "Slate", "SlateCore", "Http" });

Created functions to download the asset:

void downloadAsset(FString AssetURL)
{
	TSharedRef< IHttpRequest > HttpRequest = http->CreateRequest();
	HttpRequest->SetVerb("GET");
	HttpRequest->SetURL(AssetURL);
	HttpRequest->OnProcessRequestComplete().BindUObject(this, &OnReady);

	// Execute the request
	HttpRequest->ProcessRequest();
}

void OnReady(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{

	if (Response.IsValid() && EHttpResponseCodes::IsOk(Response->GetResponseCode()))
	{
		FString FileSavePath = FPaths::ProjectContentDir() + "Assets/" + FPaths::GetCleanFilename(Response->GetURL());

		// SAVE FILE
		IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();

		// create save directory if not existent
		FString Path, Filename, Extension;
		FPaths::Split(FileSavePath, Path, Filename, Extension);
		if (!PlatformFile.DirectoryExists(*Path))
		{
			if (!PlatformFile.CreateDirectoryTree(*Path))
			{
				GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "Download of " + FPaths::GetCleanFilename(Response->GetURL()) + " Failed!");
				return;
			}
		}

		// open/create the file
		IFileHandle* FileHandle = PlatformFile.OpenWrite(*FileSavePath);
		if (FileHandle)
		{
			// Write the file
			FileHandle->Write(Response->GetContent().GetData(), Response->GetContentLength());
			// Close the file
			delete FileHandle;

			// load the asset and assign to actor. Doesn't seem to work inside here, maybe there is a better way?
			FString assetPath = "/Game/Content/Assets/" + FPaths::GetBaseFilename(Response->GetURL());

			UStaticMesh* objectMesh = LoadObject<UStaticMesh>(nullptr, *assetPath);

			if (objectMesh)
			{
				actor->GetStaticMeshComponent()->SetStaticMesh(objectMesh);
			}

		}
		else
		{
			GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "Download of " + FPaths::GetCleanFilename(Response->GetURL()) + " Failed!");
		}
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, "Download of asset failed!");
	}
}