title: Protobuf-net [de]serialize GameObject (Unity 3D)
body: <p>In Unity 3D, there is a GameObject with a Transform property. Transform has position (Vector3) and rotation (Quaternion). I would like to send these GameObjects to/from a backing store via protobuf-net. I am currently doing so with the following code but the GameObject.transform.position.x,y,z and transform.rotation.x,y,z,w don't appear to be stored in the serialized file?</p>
  
  <pre><code>RuntimeTypeModel model = TypeModel.Create();
  model.AutoAddMissingTypes = true;
  model.Add(typeof(Vector3), true).Add("x","y","z");
  model.Add(typeof(Transform), true).Add("position").Add("rotation"); 
  model.Add(typeof(Quaternion), true).Add("x","y","z","w");
  model.Add(typeof(GameObject), true).Add("transform").Add("name");
  model.SerializeWithLengthPrefix(fs, go, typeof(GameObject), PrefixStyle.Base128, 0);
  </code></pre>
  
  <p>Deserialize:</p>
  
  <pre><code>using (FileStream fs = new FileStream(path, FileMode.Open))
  {
  fs.Position = 0;
  RuntimeTypeModel model = TypeModel.Create();
  model.AutoAddMissingTypes = true;
  model.Add(typeof(Vector3), true).Add("x","y","z");
  model.Add(typeof(Transform), true).Add("position").Add("rotation"); ;
  model.Add(typeof(Quaternion), true).Add("x","y","z","w");
  model.Add(typeof(GameObject), true).Add("transform").Add("name");
  
   do
   {
     len = ProtoReader.ReadLengthPrefix(fs, false, PrefixStyle.Base128, out fieldNumber, out bytesRead);
     if (bytesRead &lt;= 0) continue;
  
     gos.Add((GameObject)model.Deserialize(fs, null, typeof(GameObject), len));
   } while (bytesRead &gt; 0);
  }
  </code></pre>
  
  <p>I appear to be getting back the correct number of GameObjects but the only thing that is correct on deserialization is the .name property. The sub-properties of the Transform class aren't being translated with my current code.  Any ideas would be super helpful!<br>
  Thanks-</p>
  
  <h1>EDIT</h1>
  
  <p>Based on my comment, here is the stack trace:</p>
  
  <pre><code>at (wrapper managed-to-native) UnityEngine.Object.set_name (string) &lt;0x00004&gt;
  at (wrapper dynamic-method) UnityEngine.Transform.proto_22 (object,ProtoBuf.ProtoReader) &lt;IL 0x0002f, 0x00137&gt;
  at ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read (object,ProtoBuf.ProtoReader) &lt;IL 0x00008, 0x0002f&gt;
  at ProtoBuf.Meta.RuntimeTypeModel.Deserialize (int,object,ProtoBuf.ProtoReader) &lt;IL 0x0003d, 0x00143&gt;
  at ProtoBuf.ProtoReader.ReadTypedObject (object,int,ProtoBuf.ProtoReader,System.Type) &lt;IL 0x0002d, 0x000f6&gt;
  at ProtoBuf.ProtoReader.ReadObject (object,int,ProtoBuf.ProtoReader) &lt;IL 0x00004, 0x00031&gt;
  at (wrapper dynamic-method) CoreStructure.proto_20 (object,ProtoBuf.ProtoReader) &lt;IL 0x000e5, 0x005cb&gt;
  at ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read (object,ProtoBuf.ProtoReader) &lt;IL 0x00008, 0x0002f&gt;
  at ProtoBuf.Meta.RuntimeTypeModel.Deserialize (int,object,ProtoBuf.ProtoReader) &lt;IL 0x0003d, 0x00143&gt;
  at ProtoBuf.ProtoReader.ReadTypedObject (object,int,ProtoBuf.ProtoReader,System.Type) &lt;IL 0x0002d, 0x000f6&gt;
  at ProtoBuf.ProtoReader.ReadObject (object,int,ProtoBuf.ProtoReader) &lt;IL 0x00004, 0x00031&gt;
  at (wrapper dynamic-method) CharacterPoseSet.proto_14 (object,ProtoBuf.ProtoReader) &lt;IL 0x00116, 0x006e0&gt;
  at ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read (object,ProtoBuf.ProtoReader) &lt;IL 0x00008, 0x0002f&gt;
  at ProtoBuf.Meta.RuntimeTypeModel.Deserialize (int,object,ProtoBuf.ProtoReader) &lt;IL 0x0003d, 0x00143&gt;
  at ProtoBuf.Meta.TypeModel.DeserializeCore (ProtoBuf.ProtoReader,System.Type,object,bool) &lt;IL 0x00011, 0x00073&gt;
  at ProtoBuf.Meta.TypeModel.Deserialize (System.IO.Stream,object,System.Type,ProtoBuf.SerializationContext) &lt;IL 0x00022, 0x000ff&gt;
  at ProtoBuf.Meta.TypeModel.Deserialize (System.IO.Stream,object,System.Type) &lt;IL 0x00005, 0x0003e&gt;
  at PoseEditor.DeserializeCharacterPoseSet () [0x0015f] in C:\My Work\KungFuKitty\UnityWorkspace\Assets\Scripts\Editor\PoseBuilder\PoseEditor.cs:137
  
  UnityEngine.Debug:LogError(Object)
  PoseEditor:DeserializeCharacterPoseSet() (at Assets/Scripts/Editor/PoseBuilder/PoseEditor.cs:160)
  PoseEditor:OnGUI() (at Assets/Scripts/Editor/PoseBuilder/PoseEditor.cs:98)
  PoseBuilder:OnGUI() (at Assets/Scripts/Editor/PoseBuilder/PoseBuilder.cs:128)
  UnityEditor.DockArea:OnGUI()
  </code></pre>
  
  <h1>Deserialization:</h1>
  
  <pre><code>RuntimeTypeModel model = TypeModel.Create();
  model.AutoAddMissingTypes = false;
  model.Add(typeof(CharacterPoseSet), true);  
  model.Add(typeof(LegStructure), true);
  model.Add(typeof(ArmStructure), true);
  model.Add(typeof(AuxilaryStructure), true);
  model.Add(typeof(CoreStructure), true);
  model.Add(typeof(Vector3), true).Add("x", "y", "z");           &lt;-- UnityEngine
  model.Add(typeof(Transform), true).Add("name");                &lt;-- UnityEngine
  model.Add(typeof(Quaternion), true).Add("x", "y", "z", "w");   &lt;-- UnityEngine
  model.Add(typeof(GameObject), true).Add("transform").Add("name").Add("layer"); &lt;--..
  cps = model.Deserialize(fs, cps, typeof(CharacterPoseSet)) as CharacterPoseSet;
  </code></pre>
  
  <p>This is on PC/Windows 7 Box.. all code is executing inside the Unity editor.</p>