How can I resolve issues with long file paths on Windows?

Symptoms

  • Filename too long error from git when adding 3D WebView's files
  • DirectoryNotFoundException or FileNotFoundException when building for macOS on Windows

Cause

By default, Windows' Win32 APIs have the limitation that they can only handle file paths that are 260 characters or less. Due to constraints of macOS and Chromium, 3D WebView's macOS plugin contains some deeply nested files. So, unless the file path of your Unity project directory is relatively short, you may encounter errors resulting from Windows' max path limitation when dealing with 3D WebView's macOS files.

Resolution

  • In Windows 10, Microsoft fixed the max path limitation, but for legacy compatibility, they made it so that you must opt into it. This Microsoft support article describes the limitation and how to resolve it.

  • Additionally, git for Windows requires enabling long paths in its config, like this:

git config --system core.longpaths true
  • If you continue encountering issues, another option is to move your Unity project to a directory with a shorter file path.

  • Or if you're not targeting macOS, another alternative is to delete 3D WebView's Plugins/Mac directory.