Prefab works until I look at it in editor, then I get a NullReferenceException.

Hello all,

I am having a bit of a unique problem here, and I normally like to figure things out for myself, however I am completely stumped with this. I have spent hours trying to debug this, as well as looking for potential answers on the internet with no luck.

**Problem: ** The problem I’m having is with a prefab that I have set; it’s a combination of Unity’s FirstPersonController asset + a script I’ve written. Now, normally, these scripts work without issue - the prefab is loaded, the character is spawned, and all is well. However, the issue seems to be with the Editor: whenever I ‘look’ at the prefab in the Editor (usually to make slight changes), and start the game, it starts giving me NullReferenceExceptions, whereas normally, it works fine. At first I thought it was because I had made a change, so I reverted back and the problem still persisted. The problem goes away, however, whenever I:

A.) Close Unity and re-open the project,
and
B.) Make a slight modification to my code so that it recompiles.

Again, simply looking at the prefab in the Editor seems to cause this issue. I am loading the prefab via script, but I have tried doing it as a drag-and-drop reference too, but that breaks it no matter what I do. It’s like it can normally find the prefab, but after I so much as look at it in the Editor, somehow it can’t find it until the code is recompiled.

Any ideas at all?

Thank you in advance.

Anyone?

This thing says I posted it 2 days ago but it’s been a week and a half.