unity3d - Serialization misbehave when closing Unity -


i'm using iserializationcallbackreceiver serialize custom interrelated data following tutorial http://blogs.unity3d.com/2014/06/24/serialization-in-unity/ regarding serialization of graph nodes adjusting needs.

my serialization working fine when i'm hot swapping code when i'm developing scripts. once save scene, close unity , reload project again, data deserializing bogus.

[01] [17:23:43] quest[the sculpture , box|sleep]: serializing queststepdata[fqcn=experiment.questsjg.steps.gotolocation|name=sculpture|description=f|closedbyindex=-1|go1present=true|go1=sculptures_01_02 (unityengine.gameobject)|go2present=true|go2=[1] go location point (sculpture) (unityengine.gameobject)|f1=8] [02] [17:23:43] quest[the sculpture , box|sleep]: serializing queststepdata[fqcn=experiment.questsjg.steps.gotolocation|name=box|description=s|closedbyindex=-1|go1present=true|go1=box1 (unityengine.gameobject)|go2present=true|go2=[2] go location point (box) (unityengine.gameobject)|f1=4]  [03] [17:24:09] quest[the sculpture , box|sleep]: deserializing queststepdata[fqcn=experiment.questsjg.steps.gotolocation|name=sculpture|description=|closedbyindex=-1|go1present=true|go1= (unityengine.gameobject)|go2present=true|go2= (unityengine.gameobject)|f1=8] [04] [17:24:09] quest[the sculpture , box|sleep]: deserializing queststepdata[fqcn=experiment.questsjg.steps.gotolocation|name=|description=|closedbyindex=-1|go1present=false|go2present=false|f1=10] 

here log of i'm de/serializing. unity got restarted between 17:23:45-17:24:00 , can see did not deserialize (rows 03 , 04) same data serialized (rows 01 , 02).

when save scene, typically rows 01 , 02 logged.

but when these "rows" gets deserialized when open unity, rows 03 , 04 , can see row 03 "description" differs row 01 , row 04 missing except 'fqcn' field when compared row 02.

logs precise can (i'm writing them file), these serialization lines 01 , 02 should last thing unity doing data when closing...

now i'm buffled...

  1. serialization working flawlessly when hot swapping code
  2. not working when restarting unity ... (the worst thing "drops" infos)

any hints might doing wrong?

(the same happens 3+ items... 1st item somehow correct)

p.s.: not matter whether have asset serialization set "mixed" or "force text".

if have "mixed" data within scene file looks this:

the sculpture , box               !   nyŻ         stepsdata.array.data[0].fqcn&    experiment.questsjg.steps.gotolocation              !   nyŻ     %    stepsdata.array.data[0].closedbyindex      -1              !  nyŻ     stepsdata.array.data[0].f1     8               !   nyŻ         stepsdata.array.data[0].name       sculpture               !   nyŻ         stepsdata.array.data[0].go1         ^    !   nyŻ     "    stepsdata.array.data[0].go1present     1               !   nyŻ         stepsdata.array.data[0].go2         *¨    !   nyŻ     "    stepsdata.array.data[0].go2present     1               !   nyŻ         stepsdata.array.data[1].fqcn&    experiment.questsjg.steps.gotolocation              !   nyŻ     %    stepsdata.array.data[1].closedbyindex      -1              !   nyŻ         stepsdata.array.data[1].f1     10              !   nyŻ         

as can see, serialized data not there, compare stepsdata.array.data[0] , stepsdata.array.data[1]

if have "force text" data within scene file looks (it's worse):

- target: {fileid: 11499854, guid: bd017908bdedeb24d9559a160e99a0c1, type: 2}   propertypath: stepsdata.array.data[0].fqcn   value: quests.steps.gotolocation   objectreference: {fileid: 0} - target: {fileid: 11499854, guid: bd017908bdedeb24d9559a160e99a0c1, type: 2}   propertypath: stepsdata.array.data[0].closedbyindex   value: -1   objectreference: {fileid: 0} - target: {fileid: 11499854, guid: bd017908bdedeb24d9559a160e99a0c1, type: 2}   propertypath: stepsdata.array.data[0].f1   value: 10   objectreference: {fileid: 0} - target: {fileid: 11499854, guid: bd017908bdedeb24d9559a160e99a0c1, type: 2}   propertypath: stepsdata.array.data[1].fqcn   value: quests.steps.gotolocation   objectreference: {fileid: 0} - target: {fileid: 11499854, guid: bd017908bdedeb24d9559a160e99a0c1, type: 2}   propertypath: stepsdata.array.data[1].closedbyindex   value: -1   objectreference: {fileid: 0} - target: {fileid: 11499854, guid: bd017908bdedeb24d9559a160e99a0c1, type: 2}   propertypath: stepsdata.array.data[1].f1   value: 10   objectreference: {fileid: 0} - target: {fileid: 107138, guid: bd017908bdedeb24d9559a160e99a0c1, type: 2}   propertypath: m_name   value: first quest   objectreference: {fileid: 0} 

hmmmm, what's happening in there?

aaaa!

the trick call editorutility.setdirty(gameobject) every time changes page states: http://docs.unity3d.com/scriptreference/editorutility.setdirty.html

unity internally uses dirty flag find out when assets have changed , need saved disk.

e.g. if modify prefab's monobehaviour or scriptableobject variables, must tell unity value has changed. unity builtin components internally call setdirty whenever property changes. monobehaviour or scriptableobject don't do automatically if want value saved need call setdirty.

therefore, whenever you're creating customeditor following http://docs.unity3d.com/manual/editor-customeditors.html make sure use trick:

gui.changed = false;  // you're edit code here  if (gui.changed) setdirty(yourgameobjectthathasjustchanged); 

hope saves someone's time :-)

cheers!


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -