As the title suggests, I want to be able to upload a text file to my Android device, eg ‘words.txt’ and then read it at runtime. I cannot package this file with the rest of the game as it may be subject to change from external programs. However every attempt I make results in either no directory/file exists or a path that is in the unreal project directory
Unreal 5.3, I am building with SDK29 for both target and minimum and using the platform launcher to port the build to an Android v14
I have ticked the box for UseExternalFilesDir for UnrealGameFiles (though this feels unrelated)
I have added the following extra permissions
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_EXTERNAL_STORAGE
My attempts are currently using C++ function calls into IFileManager::IterateDirectory and FileExists. It seems that no matter what path I use, these functions fail, or the path is truncated to read from the project directory instead.
Can this be done? If so what is the best practice?
android changes the rules: there is no shared external storage path your game can freely read by default, and the path constants you tried (relative paths, FPaths project dirs) resolve inside your app’s private sandbox, which is why the file is not found.
what works, per android version:
android 10 and below (legacy): with WRITE_EXTERNAL_STORAGE permission declared (and runtime granted), you could use paths under /sdcard/. add the permission in project settings, android, advanced apk packaging, extra permissions (android.permission.WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE), and request it at runtime from blueprint (request permissions node) or java wrapper.
android 11+: scoped storage. direct path access to shared storage is gone. the supported routes: SAF (storage access framework, requires java-side intent plumbing through a custom plugin), or MANAGE_EXTERNAL_STORAGE (all files access, google play restricts it heavily, sideloaded builds fine), or app-specific external dir (getExternalFilesDir, accessible without permission, wiped on uninstall). for a words.txt that only your game reads, the app-specific dir is the intended solution: path typically /storage/emulated/0/Android/data//files/.
reading the file once you have a real path: FFileHelper::LoadFileToString, or FPlatformFileManager get platform file, which also lets you probe existence first. blueprint side there is no stock file read node, so a tiny c++ function library (read text file, write text file taking absolute path) is the usual bridge.
one practical note: FPaths::ProjectPersistentDownloadDir maps to the app files dir on android, which is the sanctioned spot for user modifiable files, and it exists in blueprint already.