Components losing all references in inspector
Hello,
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?
Answer by jethrogillgren · May 10, 2018 at 12:35 PM
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.
Thanks I had the same issue when i upgraped all of my externals DLLs, just reopening the editor fixed it
Answer by Trinary · Jun 17, 2016 at 04:50 PM
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 do no such thing as moving the files around, and I get the same problem. It's more than just annoying, it's a great loss of time to have to re put all the data again in there every few dozen of $$anonymous$$utes. I also tried to copy the meta files to put them back faster, but unity erased them as well, for some reason.
This happened to me after an upgrade and I seriously panicked. Started thinking about how stupid I was for not updating like the smart prompt told me to.
Then I saw your comment, big sigh of relief when I tried it and it worked.
Answer by rayuthebest · Dec 26, 2017 at 10:40 AM
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?
thanks, its work for me, i just save sprite every json modification, because otherwise it loads the default image, and not the image that I had already modified
Your answer
Follow this Question
Related Questions
How to break reference from .asset classes and runtime copied values? 2 Answers
Use c# "ref" with a GameObject or Component 1 Answer
MonoDevelop can't find references for scripts in Editor folder 0 Answers
How to Serialize or Save a List of GameObjects 1 Answer
.data serialize and deserialize work in editor but not in build 1 Answer