Hey guys I seem to have ruined everything and I can’t figure out how in THE WORLD I managed to make this mess happen.
I’ve been working with Unity since version 4.x, probably earlier, and I’m very good with C#. I have a big project that I’ve been working on for years. And suddenly today, I discovered, that it doesn’t work if I run it by actually double-clicking the exe file in the build folder. But it does run, just fine in fact, if I run it by clicking “build and run” in the file menu of the editor! Sound weird yet? Well it gets weirder.
I have an error logger I made for it, which saves any error messages that would have been written to the console. So even though it’s a build running outside of Unity, I can still whip up my error log. And so I’ve output error messages at the locations where it is getting stuck, and basically…
It thinks that EVERY class that I set up at the top of any of my CS files, using a line such as:
private Class_Name myCoolClass = new Class_Name();
Well, in any function calls, it thinks myCoolClass is null.
Likewise, any thing that I set up in any constructor function, such as:
Class BLEH : Monobehavior
{
public BLEH() {
something_import = new stuff();
}
}
…AND then it thinks something_important is also null.
This is baffling to me. I know how to C#. I’m not some stupid noob who doesn’t understand what he is doing. This shouldn’t be happening. This code has been working for years just fine. And now all of a sudden I’m being spammed with errors EVERYWHERE, basically that everything that should be constructed, is all null reference errors.
This initially was happening in 2018 unity editor, which I was still using. So I did a “reimport all”, which fixed nothing. So in desperation, I downloaded 2019.2.12f1, and imported the project into that, which ran it’s automatic upgrade, and there were no errors in the upgrade (a first). But running it in 2019 gave the same errors.
Here’s the thing, when I start the program using the file → Build and Run button, it runs just fine and everything is constructed and there are no errors at all.
But then, when I actually browse to the file on the hard drive in the build folder, and double click the exe, then it has null references galore. I’ve been double checking about 20 times that I am indeed actually double clicking the correct exe, the same one that was built by the “build and run” button. It’s definitely the same exe. I even checked it in Process Explorer to absolutely confirm that I’m running the same program.
The only difference that Process Explorer reveals, is that when I click “Build and Run”, the program is listed as a sub-process beneath the “Unity.exe” process. Which makes sense, if you know how that works (a parent process that opened a child process).
Whereas if I open the exe by double clicking it in the folder, then it is listed beneath “Explorer.exe”, which also makes sense. But what doesn’t make sense is that it would fail all its constructors when I double click it, and run just fine when I run it through “Build and Run”.
I’m starting to wonder if I am going crazy. How is this even possible. Is the matrix real? O_O
I guess I’ll just keep beating my head against the desk until I find some answer to this. But if anyone has any theory on what might be the cause of this, please, only you can prevent the flattening of my facial features.