I have a simple Unity game with a single scene, which I am trying to build for Windows:

enter image description here

When I click "build", I am prompted to select a folder. I choose an empty folder and click "Select Folder". Then I see some pop-up messages as well as this warning:

enter image description here

But, the folder remains empty - nothing is built there.

How can I debug this error?

EDIT: I tried to build from the command line:

Unity -batchmode -projectPath D:\gamedev-code\01-unity-basics -buildWindows64Player D:\GameBuilds\01-basics-windows\

I got an error:

Aborting batchmode due to failure:
Failed to build player.

which is not very helpful..

  • 2
    \$\begingroup\$ Did you happen to select a folder inside your assets directory, causing Unity to think the build being written was a new asset to import? \$\endgroup\$
    – DMGregory
    Feb 21, 2023 at 15:14
  • \$\begingroup\$ @DMGregory No: the folder is D:\GameBuilds, that I created specifically for game builds. \$\endgroup\$ Feb 21, 2023 at 18:02
  • \$\begingroup\$ I tried to build a different Unity project into the same folder, and it worked just fine. Is there a way to build a game from the command line, so I can see if there are any error messages? \$\endgroup\$ Feb 22, 2023 at 16:54
  • \$\begingroup\$ Error messages should be printed to the console window and editor log. But if you want to build from the command line, a quick search will lead you to the command line arguments you need and tutorials for how to use them. \$\endgroup\$
    – DMGregory
    Feb 22, 2023 at 17:00
  • \$\begingroup\$ If you can build another project, then one way you can narrow down the problem here is to start copying content from the project that won't build into the project that will. Every so often in that process, try to build again. If you hit a point where the build stops working, you know something in the last batch of additions is related to causing the error, and you can look closer at that content to try to distill it down to a Minimal Complete Verifiable Example. If you don't hit a spot where the build stops working, then you can set sail in your brand new ship of Theseus project. \$\endgroup\$
    – DMGregory
    Feb 22, 2023 at 17:24

1 Answer 1


The problem was a compilation error in a script I did not use.

I did not notice it before, because the scene runs fine without this script.

I have learned that, when building a game, Unity tries to compile all the scripts - even those not in the scene.

  • \$\begingroup\$ It has to do that since you can have more than one scene in your build. \$\endgroup\$
    – Zibelas
    Feb 23, 2023 at 19:21
  • \$\begingroup\$ Moreover, it's not always possible to determine whether a script is used or not (this comes down to the Halting Problem - you could have code that fetches a reference to the script by reflection, using a string that's composed at runtime, etc...). So "Compile everything, then strip out the subset of code we can verify is dead" is about the best policy we can use. \$\endgroup\$
    – DMGregory
    Feb 23, 2023 at 19:43
  • \$\begingroup\$ If a script is not referenced at all, I do not see why it should be compiled. \$\endgroup\$ Feb 25, 2023 at 18:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .