Inspector loose data after git branch switch
I have two git branches. At first i have no some serializable fields in object. So when i chekout to second branch where these fields are present (hot project reloads happend), inspector not shown their values (like they are empty) and in play Mode they are empty too. But if i checkout this branch and after it load unity app - everything is normal. I think project reloading works incorrect. But maybe i'm doing something bad? Its very annoing because you might loose your data. If you change something in this object after hot reload.
public WorkerLimits workerLimits;
[Serializable]
public struct WorkerLimits
{
public int freeWorkers;
[ArrayElementNaming(elementText = "Additional worker", offset = 1)]
public AdditionalWorker[] additionalWorkers;
}
[Serializable]
public struct AdditionalWorker
{
public ItemStack[] cost;
}
/.temp
/.sdk
/.dart.user.options.json
.DS_Store
.idea
__pycache__
ImportSetting.asset*
*.DotSettings
Server/obj
Server/bin
Project/StaticData
Project/*.plantuml
Version$$anonymous$$anager/obj
Version$$anonymous$$anager/bin
Project/Bundles
tools/edart/obj
tools/edart/bin
*.user
Version$$anonymous$$anager.zip
Version$$anonymous$$anager/vm
/Server/.vs
/Version$$anonymous$$anager/.vs
Project/Assets/BuildReports
BuildReports.meta
That's expected behaviour. Changes you do in one branch shouldn't apply to other branches by default. The changes you describe are saved in seperate files Unity makes (e.g. .unity , .meta) and git seems to be tracking their states (one with the assigned fields you speak of and another with no data). Solutions are:
- You could just re-assign your empty fields in your other branch and commit/stash them.
- You could have these assignments in the Inspector as staged changes (don't commit them) and as you switch branch the staged changes can be carried over. This methods does seem to attract conflicts, so be careful.
- You could add the file to .gitignore, forcing git to stop tracking it and thus, any changes in that file will be same for all branches (since it's not under version control anymore). For scene-specific changes on gameobjects (e.g. assigning reference of one gameobject to a component of another in the scene) the data is likely to be saved in the .unity file of the scene. The rule in .gitignore would look like /[Aa]ssets/**/*.unity
. Do take note that you might need to run git rm --cached [file]
after adding the rule.
I will try to explain other way. I added some fields with values in my working branch and commit them: After that i switch to main branch to do some work and return back to working branch and see:
In Asset file i see:
workerLimits:
freeWorkers: 1
additionalWorkers:
- cost:
- stackType: 1
itemId: 0
index: 0
amount: 50
It's the same branch, but in Inspector these values are reseted. (Hot project reloading find new fields , but not read values which set in asset file) If i will restart Unity app everything will restore like on a First screenshoot.
Sorry for my English.
Ok, I didn't get that you return to your working branch from your original post. It seems odd that you have to restart Unity to brink the Inspector values back after returning to your initial branch. I do not seem to have such issue using this manual and this .gitignore (if you haven't checked them out already). Unfortunately, I'm not able to help you anymore and hopefully, someone more knowledgeable will be able to.
Your answer
Follow this Question
Related Questions
How do I fix broken inspector in unity? 1 Answer
Animator StateMachineBehaviour scripts are collapsed in inspector 0 Answers
Inspector overlapping component problem 2 Answers
Unity not Version Controlling Inspector Settings for GameObjects 1 Answer
Inspector assigned variables not assigning in build 0 Answers