- Home /
The question is answered.
Script Crashing (Only on first run)
I have a unity project, that when I run it in the editor with script A, it crashes on the first run of that unity session.
If I disable script A in the Inspector for the first run, the project runs fine. If I re-enable the script for the second run the project works fine (in the same unity session, i.e. without opening and closing the program).
I have commented out all of the body code in script A and it still crashes, I have moved it to the front and back of the execution order and it still crashes.
The script contains a void Start() and void Update().
Any ideas as to what is causing this?
edit: The key is that it only crashes (no console output, just crash) if I have it enabled during the initial/first time I hit play in the unity editor (I just did another test and if it is disabled and I enabled it after the editor is in the play mode, it works fine).
edit (2): Now it is crashing even if the script is disabled or removed from the scene.
edit (3): I noticed the crash started happening after using a USB controller, though I can't confirm if this is what caused the crash. I sent a report to Unity, so we'll see. Will post if I figure out the cause.
edit(4): Unity got back to me, after deleting my Library folder, everything was working as expected.
edit (4): Unity got back to me, deleting the Library folder did the trick. They also suggested upgrading my Unity (i'm on windows 7).
edit (4): Unity got back to me, after deleting the Library folder everything was working as intended, closed question.
Answer by Agent27765 · Sep 26, 2017 at 02:26 AM
Maybe you can copy the code and make a new script file and see if that works. It seems that the script page itself is bugged. Has this ever happened to you with another script in your project?
Answer by nocoast · Sep 26, 2017 at 03:12 AM
I just copied and pasted the code into a new file, same issue.
The key is that it only crashes (no console output, just crash) if I have it enabled during the initial/first time I hit play in the unity editor (I just did another test and if it is disabled and I enabled it after the editor is in the play mode, it works fine).
Does the unity editor load code differently the first time/at the beginning of a play session?
Follow this Question
Related Questions
Changing default animation type to Humanoid via script 1 Answer
How can I overwrite .asset using AssetDatabase.CreateAsset? 2 Answers
How do I solve a BuildAssetBundles Compilation Error that only occurs in the Editor? 1 Answer
Script works in Game View, but not in build 0 Answers
Can I know why I can't control volume of audiomixergroup without exposing parameters? 0 Answers