Serialized variables often end up cleared in the Unity inspector after changing branches

Hey,
I have various scripts that have public references so I can assign objects/scripts/references in the inspector in Unity. Often when I change branches, and return to a scene weeks or months later, these references are all cleared, leading to a lot of headache. Any idea as to what is causing this?

I have attached a screenshot to show what I mean. The variables are all marked as serializable in the script, along with the relevant type.

Eg @serializable(TypeOfObjectHere)

Hi Nostalgicbear,

The issue of serialized variables being cleared in the Unity Inspector after changing branches may stem from various causes. Here are a few things to check:

  1. Script Changes: If there are changes in your script that alter the class structure or variable names (e.g., renaming fields, changing their types, or modifying serialization attributes), this can lead to lost references.

  2. Delta Serialization: Unity uses a serialization system that can sometimes get confused, particularly if the meta files differ across branches. Ensure that your .meta files are consistent and not overlooked during branch changes.

  3. Prefab or Asset Changes: If your public variables reference prefabs or assets that are changed in a way that alters their references, these links can break.

  4. Version Control Settings: Check that your version control system is properly tracking .meta files, as these are essential for keeping track of asset settings and references.

  5. Serialized Field Attributes: Ensure that you are using the correct serialization attributes. For instance, using @Serializable correctly on public fields is crucial for Unity to preserve these references.

  6. Branch Merges/Mismatches: If branches do not consistently contain the same changes to these assets and scripts, this can lead to references being cleared.

Consider reviewing the changes made in the branches using your version control system to identify any modifications that might affect your serialized references.

If the problem persists, you can also consult the documentation for serialization management in Unity to see if there are specific recommendations for handling serialized data across branches.

Let me know if you’d like more detailed guidance on a specific area!

1 replies left - Get a PRO license for more AI replies.
thread_UGdITkeLcdlUzUZ7Uka6Jtfc
Reply to this message to continue the conversation

Hello @nostalgicbear I can assure you that we don’t touch any of these values or properties!

Is it possible that your different branches don’t have the correct data serialized? Any error/warning in Unity? Which Unity version is it?

@serializable is only used in Needle Engine in the browser and does have no effect to your Unity scene. We only ever read your data but never write anything.

Hey Marcel,
The branches definitely have the data serialized.

Thanks for confirming its not Needle related though. That at least narrows down the scope for us. Its been happening infrequently, but enough that its caused some headache at times. I cant see any output in the console implying anything is wrong.

Thanks for the update. :slight_smile:

Ok, would be interesting to hear what the reason was once you know more! Which Unity version are you currently using?

Using Unity version 2022.3.12f1 for this.
If I get to the bottom of it today, I’ll update this card for anyone else that may encounter the same issue.

On a complete other point, is there planned support for the Canvas Slider? (I am on Needle 3.45.2) so apologies if this is available already in a later version.

A UI update is on the roadmap: Needle Roadmap
Please vote for the items that you’re interested in :slight_smile: