Components losing all references in inspector


on semi-regular occasions, all instances of random components will lose all their inspector data

For instance this morning, all instances of our “fit background to camera” script and our “show icon if game object is active” scripts lost all of the data that was assigned to them in the inspector

this was after newly booting the scene this morning and it appears that this data was lost from the save file as reloading unity does not fix the issue

as this happens every few weeks on entirely random game objects (sometimes NGUI components, sometimes our own scripts, usually code that hasn’t been touched in months) it is becoming quite a hassle to fix this

is there any indication as to what might be causing this?

Closing and opening Unity just fixed this for me.

I had lost all refs after updating an asset, which triggered an API Upgrade, fixing some errors and Re-opening the project.

All scene refs were gone, as you describe.

I closed and opened Unity and all the references came back - worth a try before you panic and roll back your scene.

This is typically caused by not paying attention to the fact that unity generates a meta file for each file in your project. The meta file contains an id for that file, and unity uses that id to keep all the references linked up. If you move or rename a file without also moving or renaming the meta file then this id will be lost as soon as you select the Unity window. Unity will generate a new meta file with a new id, and all the links will be broken.

I got this same behaviour some random times and the only solution that I had found is generating a prefab with the objects that contains the references.

If the prefab contains all components referenced, they are not lost when this random event happens, while references to components outside the prefab are reset (references to prefabs are not lost although they are not placed on the scene).

I good trick to know if a prefab is well defined is checking if all references are marked as normal. Bold references are outside the prefab, and they may be reset.

Has anyone found a best solution?