Is there anything special that has to happen to enable nested serialization of objects?
I have a Party object on the server, and it contains an array of PartyMember objects. When I send the Party object to the client, Unity's OnExtensionResponse never gets triggered. I don't receive any exceptions on the client or server, and logging indicates that everything proceeded as planned. Sending just a PartyMember object seems to work fine.
I'm following the steps listed in the documentation and in Thomas's post on Sending/receiving classes. His example doesn't contain an array of serializable objects, though...is that allowed?
Serialization of nested classes
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
Hmmm - got some more details on what you exactly are sending?
Also beware that the class serialization stuff doesnt allow for generics (yet?). So that might be your issue.
Else paste a few code snippets!
/Thomas
Also beware that the class serialization stuff doesnt allow for generics (yet?). So that might be your issue.
Else paste a few code snippets!
/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Follow on twitter: http://twitter.com/thomas_h_lund
The PartyMember object:
Then I wanted to have a Party object which contained an array of PartyMembers:
The ideal implementation for the partyMembers variable would have been a Hashmap<Integer, PartyMember> since the indices will often have gaps and not be sequential. Since your notes mentioned needing to use a Hashtable indexed by strings only, I thought an array would be more appropriate here.
After some fiddling, I got an error to show up in the server logs, mentioning that PartyMember[] did not implement SerializableSFSType (even though the PartyMember class did). Wasn't sure what to make of that, and ended up going with the less desirable Hashtable.
Code: Select all
public class PartyMember implements SerializableSFSType {
public String name;
public int portrait;
public int type;
// Necessary for serialization
public PartyMember() { }
public PartyMember(String name, int portrait, int type) {
this.name = name;
this.portrait = portrait;
this.type = type;
}
}
Then I wanted to have a Party object which contained an array of PartyMembers:
Code: Select all
public class Party implements SerializableSFSType {
// The list of PartyMembers in this Party
public PartyMember[] partyMembers;
// The maximum size of a Party
public int MAX_SIZE = 10;
// Necessary for serialization
public Party() { }
// Create a brand new party
public Party(String name, int portrait, int type) {
partyMembers = new PartyMember[MAX_SIZE];
partyMembers[0] = new PartyMember(name, portrait, type);
}
}
The ideal implementation for the partyMembers variable would have been a Hashmap<Integer, PartyMember> since the indices will often have gaps and not be sequential. Since your notes mentioned needing to use a Hashtable indexed by strings only, I thought an array would be more appropriate here.
After some fiddling, I got an error to show up in the server logs, mentioning that PartyMember[] did not implement SerializableSFSType (even though the PartyMember class did). Wasn't sure what to make of that, and ended up going with the less desirable Hashtable.
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
Will put your example through some paces here as a test case.
Thanks
/Thomas
Thanks
/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Follow on twitter: http://twitter.com/thomas_h_lund
Who is online
Users browsing this forum: No registered users and 52 guests