Can't package project due to failed stage directory.

Hi, I am trying to package my game but I am getting stopped by these errors

UATHelper: Warning: Packaging (Windows): Failed to delete directory C:\Users\shawn\OneDrive\Documents\Unreal Projects\OffMyGarden\Saved\StagedBuilds\Windows\Engine\Binaries\ThirdParty\DbgHelp in 10 attempts.
UATHelper: Warning: Packaging (Windows): Exception in System.Private.CoreLib: Access to the path '\\?\C:\Users\shawn\OneDrive\Documents\Unreal Projects\OffMyGarden\Saved\StagedBuilds\Windows\Engine\Binaries\ThirdParty\DbgHelp' is denied.
Stacktrace:    at System.IO.FileSystem.RemoveDirectoryInternal(String fullPath, Boolean topLevel, Boolean allowDirectoryNotEmpty)
   at System.IO.FileSystem.RemoveDirectoryRecursive(String fullPath, WIN32_FIND_DATA& findData, Boolean topLevel)
   at System.IO.FileSystem.RemoveDirectory(String fullPath, Boolean recursive)
   at AutomationTool.InternalUtils.SafeDeleteEmptyDirectory(String Path, Boolean bQuiet)
UATHelper: Error: Packaging (Windows): Stage Failed. Failed to delete staging directory C:\Users\shawn\OneDrive\Documents\Unreal Projects\OffMyGarden\Saved\StagedBuilds\Windows
(see C:\Users\shawn\AppData\Roaming\Unreal Engine\AutomationTool\Logs\C+Program+Files+Epic+Games+UE_5.7\Log.txt for full exception trace)
UATHelper: Packaging (Windows): AutomationTool executed for 0h 0m 49s
UATHelper: Packaging (Windows): AutomationTool exiting with ExitCode=102 (Error_FailedToDeleteStagingDirectory)
UATHelper: Packaging (Windows): BUILD FAILED
PackagingResults: Error: Failed to delete staging directory.  This could be because something is currently using the staging directory (ps4/xbox/etc)

Anyone know how to help?

Hello there @Shawn.O!

From that log extract, UE is trying to delete a previous staging build, and unable to do so, because access to the location is being denied. And the reason for that, is most likely due the fact that your project is inside the OneDrive directory.

And since your project is located in a cloud-synced folder, the files in there are being locked out as soon as they are created, cause OneDrive starts uploading them as soon as they pop up. So, the most direct solution would be to move the project to another location. Now, if you must have the project synced, then pause OneDrive during packaging, and re-enable it once the process is completed.

If you end up migrating the project to another location, please don’t forget to clear up it’s cache, as the old locations will still be stored there, and that will result in other types of crashes. To do the clean up, navigate to your project’s new main directory, and delete folders Saved, Intermediate, and DerivedDataCache. Once that’s done, re-open the project, allow it to rebuild, then test packaging again.