UE4Game folder on External Storage -

Hello UE Team, I wanted to know whether it’s possible to prevent a ue4 game to create a folder (UE4Game and its content) automatically in External storage? I want to have it on internal data folder (like /data/com../UE4Game/) so the user can’t see the save games easily (e.g)

1 Like

Same question. Another pain is that when app was uninstalled, the UE4Game folder will not be auto removed. I think that is a bad user experience. Why design this like that? Is there any pros or limitation?

I found a global variable GFilePathBase at line 865 in file \Engine\Source\Runtime\Launch\Private\AndroidJNI.cpp. It is assigned to ExternalStorageDirectory(/storage/sdcard0) of . And another global variable GExternalFilePath at line 926 is assigned to ExternalFilesDir(/storage/sdcard0//data/package/files), I think this is what we looking for. But now I don’t have any idea to modify it to suit this purpose. Maybe someone else has any idea or experience?

1 Like

I edited those variables. Now I’m trying to build the engine. Hoping for no errors :slight_smile:

Unsuccesful with building engine from source code **for **

Can someone from Epic please answer this

Any files placed in GExternalFilePath will be cleaned up when the APK is uninstalled. You can make this change in AndroidJNI.cpp to ue4_GameActivity_nativeSetGlobalActivity after GExternalFilePath = FString(nativeExternalFilesPathString):

#if UE_BUILD_SHIPPING
GFilePathBase = GExternalFilePath;
#endif

This will use the external file path for shipping builds. You don’t want to do this for launch-on since it expects to find the pushed files in the normal location.

I am planning to provide this as a checkbox option in 4.15; the feature set for 4.14 is already locked down.

After I did that, an error message showed up when I launched project on device.

How can I fix this?

Thx

Ok, better I wait until version 4.15. I’m unsure while editing the source code, so I let the Epic developers do that.

I believe you have an OBB outside of the APK and it is failing to mount it. There is a fix, but it involves a few more changes.

In AndroidFile.cpp:

add FString GFileExternalStorage; before

// External File Path base - setup during load
FString GFilePathBase;

Then change

FString OBBDir1 = GFilePathBase + FString(TEXT("//obb/") + GPackageName);
FString OBBDir2 = GFilePathBase + FString(TEXT("/obb/") + GPackageName);

to

	FString OBBDir1 = GFileExternalStorage + FString(TEXT("//obb/") + GPackageName);
	FString OBBDir2 = GFileExternalStorage + FString(TEXT("/obb/") + GPackageName);

In AndroidJNI.cpp:

add extern FString GFileExternalStorage; before extern FString GFilePathBase;

add 'GFileExternalStorage = GFilePathBase; after GFilePathBase = FString(nativePathString); in JNI_OnLoad().

Now it will still be able to access the OBB.

It works!
Thank you!

Hi Chris, thanks for the solution. And I wanna confirm one thing that is this will certainly add into UE4 in version 4.15?

Yes, it is a checkbox in 4.15.

There are serious problems.
If user doesn’t have external sdcard, UE4Game folder is created in Internal storeage and It will not be removed when uninstall.
And another problem is that All game resource images are shown in gallery app.

I hope these Problems will be fixed in 4.15

Hi Chris, thanks for the solution. But how to compile after modify the AndroidFile.cpp ? Is open the UE4.sln to do compile?

Of course, that is one of the file in engine sources.

Thanks a lot, wingedrobin :smiley:

Hi, Chris.
Is this the checkbox that you said?

221614-not-install-at-ext.jpg

If yes, is the functionality implemented yet? No matter i check or uncheck the Use ExternalFilesDir for UE4Game files, the UE4Game folder is always be created outside of the /data/ folder.

There will create UE4Game and obb two folder under /storage/sdcard0, and create a game project folder under /storage/sdcard0//data but only contain ca-bundle.pem and login-identifier.txt two files. All files of project are still placed in /storage/sdcard0/UE4Game, not in /storage/sdcard0//data.

And the Install Location option on the picture seems no use either. So is the only way that I want to place my whole game content into /storage/sdcard0//data folder is to modify the source code of the engine??

PS: I tried in development build and shipping build are the same result.

wingedrobin give right answer. If you want use internal storage for UE4Game set true “Use ExternalFilesDir for UE4Game files” and in shipment will be using internal storage. In another build will be using external storage.

You can see is UE4 sources.
https://github.com/EpicGames/UnrealEngine/blob/c3caf7b6bf12ae4c8e09b606f10a09776b4d1f38/Engine/Source/Runtime/Launch/Private//AndroidJNI.cpp
in JNI_OnLoad setting GFilePathBase

GFilePathBase = FJavaHelper::FStringFromLocalRef(Env, (jstring)Env->CallObjectMethod(*externalStoragePath, getFilePath, nullptr));

And GFilePathBase use for set on platform FilePathBase and BasePath when bUseExternalFilesDir is true
in Java_com_epicgames_ue4_GameActivity_nativeSetGlobalActivity

if (bUseExternalFilesDir)
		{
#if UE_BUILD_SHIPPING
			GFilePathBase = GInternalFilePath;
			GOverrideAndroidLogDir = bPublicLogFiles;
#else
			GFilePathBase = GExternalFilePath;
#endif
			FPlatformMisc::LowLevelOutputDebugStringf(TEXT("GFilePathBase Path override to'%s'\n"), *GFilePathBase);
		}
1 Like

Reviving this ancient post to inquire about this once again, this time for 12.

Because of the error from the post by @anonymous_user_d263f0c4 in 2016 (Failed to open descriptor file) I have no choice but to completely package my game. (launcher will cause this error regardless of shipping/development build type.)

However, I cannot seem to get save games to work correctly, regardless of what settings I run. I have tried every possible combination of development/shipping/distribution and ExternalFilesDir / Install Location. Nothing will let me even use a save game file on 12. I have also tried a flurry of permissions, both requesting them via blueprint node and adding them to the additional permissions in the project settings.

I’ve seen various “hack” fixes across the forums involving hardcoding the scoped storage directory into save-games and rebuilding the engine, but I can’t get any of those to work either… and they aren’t very scalable.

Any help from Epic or any other dev’s would be awesome.

1 Like

Like Dertosh, I came across bUseExternalFilesDir in my travels to realise it instead means bUseInternalFilesDir in Distribution Shipping builds only.

So if you’re running BuildCookRun, be sure to build for Shipping and add the -distribution parameter to the end of your build command (or enable “For Distribution” in the packaging window), as the MakeApk code in UEDeployAndroid.cs will set bUseExternalFilesDir to false if not building in distribution mode.

Additionally, if like me, you decided to put an inline comment after the property in the config file like so:
bUseExternalFilesDir=True ; Need this for Save Game
Remove the comment, as apparently the UEDeployAndroid.UseExternalFilesDir method was still returning false for me due to it.

Note: Leaving this here for any folks coming from search engines. I had to enable this option to get my Save Games working in when WRITE_EXTERNAL_STORAGE needs to be disabled (a requirement of Meta/Oculus Quest’s VRC).

2 Likes