Engine breaking bug : Unity scene's instantiation is completely broken. (Temporary fix found, but not permanent)
Okay, First, thanks for reading this.
I would like to mention that I got absolutely no idea about "why" this is happening, but it is and I have been looking around for possible solution or even just an idea of what is happening for a whole day.
The thing is, it seems like, since this morning, Unity can't seem to manage its scene asset correctly anymore. When one error is "fixed" (or evaded), another pop-up and, by the end, all point toward how Unity initiate a scene.
There's the problem : Unity seems to destroy and rebuild assets in the scene for no reason at all. - At first, it started with something as simple as "PlayerCharacter = GameObject.FindGameObjectWithTag("Player");" not finding the prefab of the player (which is the only asset in scene with a "Player" tag). - Then it started to find a hidden (Clone) of it which, when looked at (double click on it through a reference in the inspector), it seems to be a clone of the original model (not the prefab). Note that the asset in the scene is the prefab with multiple scripts attached to it.
Up to this point, restarting Unity seemed to fix to problem for a single try. After launching the preview a second time, the error came back.
After a while, it seems like it find a "Missing (GameObject)".
Now it's not even finding anything at all. (None)
At first, I though it was an issue with how the camera (which has the script that looks for the player) was launching its "Awake()" before the player's (which includes some stats), but then I remembered that the camera doesn't even have its script attached on launch and that it's actually the players' script that add the camera managing script onto the main camera of the scene once it completed in getting its data. So, that means the Camera only gets its Awake() method read once the Players' Awake() method has passed since the script is only added by then.
So, I build a Scene manager script that instantiate things in a specific order. It didn't do anything differently and the errors still are showing around. (Mostly, missing references errors around the player not being found.)
I read around about how the "Player" tag seems to be buggy at times and using a new one (like "player") fix it. It did fix some part of another issue that appeared, but still, it seemed like I couldn't get a component in the player's prefab as it always returned None, Missing or (Clone) without changing anything... just by restarting Unity and relaunching the scene.
Then, for the sake of testing it out, I made it so that whenever "PlayerCharacter = GameObject.FindGameObjectWithTag("player");" return anything that includes "(Clone)", to destroy that clone and do a search again. This made Unity hang and crash with the same behavior as if it was charging the script an infinite amount of time. It also means that Unity wasn't able to find an existing asset in the scene by tag.
I finally found a turn-around-solution by forcing the actual Prefab's script which add the camera manager script onto the camera to also include the reference to the prefab's GameObject itself when the function is called. This worked and all is currently working as it was working for a month up to this morning.
The "only" hint I got about what could have triggered this is that as I added some new animations to the player character (not directly within the prefab related file), I noticed some bad mesh skin topology (while testing an animation) and fixed some of the skinning. I rebuild the whole prefab manually from the new model file I exported, added the same scripts, then as I tried it, the errors started. (All animations are saved in a set of separate files and only include the bones/armature structures. The original mesh file of the prefab only includes the character in a T-Pose.)
I was wondering if it's related to some corruption in the temporary files stored by Unity which then seems to stuck itself with some old version of a file (the (Clone), then missing references as an hint). Is there a way to clean all Unity's cache as this problem might have been related to the change I have made to the player mesh?
Have anyone ever seen this problem?
Your answer
Follow this Question
Related Questions
Unity PERSISTENT error: Assertion failed on expression: 'VCCache::instance != NULL' unity 0 Answers
Unity Editor Text Goes Crazy 0 Answers
(Android) Unity crashes on building process 0 Answers
Unity 5.2 Freezing when Resizing Game View after Play 0 Answers
Unity Cache Server on Personal License? 0 Answers