We’re using nested prefabs a lot. Since a couple of Unity 2019.4 releases, I am noticing that every once in a while references in these prefabs get lost, although the prefab structure seems to be ok. Sometimes, they even look fine in the editor, but lead to NullReferenceExceptions when exported and run on a mobile device.
Only if we delete the “Library” and “obj” folders and force Unity to rebuild the internal data structures from scratch, things get back to normal. So we now decided to do this every time before we create a production build. But if you forget to do this, it may render the whole app broken.
Another thing we noticed by inspecting our git diffs is that our main scene keeps overriding all RectTransforms of one particular prefab every time we open the app and save the scene, without any user interaction. Sometimes, these rects are overridden with slightly modified floating point values, which look like rounding errors. Maybe it is related to us using HorizontalLayout and VerticalLayout components?
I am wondering what is causing these strange behaviours and how we can get rid of them? Rebuilding the whole prefab structure is not an option to us, this would be a nightmare.
I’m curious if any of the data contained in your prefab happen to cross assemblies? That is: the type being pointed to that suddenly becomes null is in another assembly. My theory for a while has been that objects are being loaded before their assemblies have which Unity resolves as “this is null”. I don’t have enough to prove it but I thought I’d ask since this seems like a pretty clear cut issue for you.
Unsure if it is related to assemblies. In general, I am using quite a number of plugins, even native ones.
Prefabs also seem to break if you switch git branches. I had the case today that doing this broke the reference to a prefab inside a prefab completely. It showed up as missing on the disk, although it was there. I only noticed this because the app behaved weirdly, this kind of errors is super hard to track down or even notice in the first place. After deleting all temporary Unity folders (Library, obj, Temp) and thus forcing Unity to rebuild its internal structures, the prefab reference was restored.
Yes, as mentioned most common reason for reference to get lost is version control operations. We try really hard to make sure prefabs depends on scripts and thus they will reimport when there are script changes.
Most of these dependency issue have been fixed but require that you switch your project to use the new asset database implementation. We know some are still experiencing these issues, unfortunately they are really hard to reproduce but we are trying.
@SteenLund : Thanks for that additional info. Glad you’re working on it. How can I do this switch to the new database? I thought this was done automatically.
Is there a way inside Unity to do this? So far, we’re deleting the Library and obj folders, but it takes Unity ages to rebuild them. If there’s an easier way to recompile all prefab dependencies, I’d be very happy to know about it