Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by knoggly · Mar 04, 2010 at 08:34 PM · networkserializationrpc

send complex objects over RPC

Hello,

are there any good solutions to send complex objects (e.g. custom playerInfo-Class) through a RPC. The manual states that RPC-Parameters can only be of simple types like string, float, etc.

a) My first idea would be to serialize the complex object to XML or JSON, send it as String through the RPC and deserialize it on the other side.

b) Other Idea: Is it possible to use an existing unity-networkview and access it's raw socket-connection and send data over this connection?

Are there better/more performant ways to do this?

The RPC's are not called frequently, just at level-start/level-end (or something similar).

regards

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by jashan · Mar 04, 2010 at 10:05 PM

How "complex" do you want these classes to be - and how complex do they really need to be?

What I'm doing for Traces of Illumination is simply have a couple of RPCs with a lot of parameters each parameter representing one member variable of the objects I want to transmit. As in your case, these objects are usually just transmitted once during login (there, you get a lot of objects) and then when another player logs in (one PlayerInfo to all existing players). So it's not really a problem.

And usually, you shouldn't have too many member variables that really need to be transmitted. I haven't counted but I think those are around 5 to 15 parameters (and it's all simple types because my member variables are only simple types).

If you need "structures" (like, I have GameGroups, Teams and Players, each game group has multiple teams, each team multiple players), you can have custom IDs that you transmit via multiple calls ("RPCAddPlayerToTeam(int playerID, int teamID)") - then, of course, you'll usually want to use some sorts of lookup tables to get everything together (but usually, you'll need such lookup tables anyways). I'm using the same RPCs here for initial transmission of the structures to new players that I'm also using when actually creating the structures in first place (one could probably use buffered-RPCs but I just don't trust those ;-) ).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Ashkan_gc · Mar 04, 2010 at 08:48 PM

you can create your own connections and use System.Net.Sockets in whatever way you want but you can not access the socket of networkViews. the first solution is the best one. serialize the class and send it and deserialize it again. you can just create a string of variables that you need and not all of them to save bandwidth.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Murcho · Mar 05, 2010 at 03:20 AM

In my previous project we tackled this problem by serializing into XML strings like you suggested, however there is a limit on how long the string could be, so simply by testing for this limit before sending, we fixed this by sending an int in the first packet as well which told the recipient how many strings to expect before joining and de-serializing the data.

We only used this for loading information, basically we had a modular weapon system and it sent the data of how to put together the client's weapon. For anything you need to send regularly I would recommend simplifying your data as much as possible as this requires a lot of work on the CPU side with string manipulation.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Lance Sun · Mar 05, 2010 at 06:20 AM

To serialize objects to xml, try xstream-dot-net (http://code.google.com/p/xstream-dot-net/)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image knoggly · Mar 05, 2010 at 07:32 AM 0
Share

allright, thanks for your answers/ideas

cheers

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Acess server stuff by the client 0 Answers

How to use Unet to send network messages like RPC (Javascript) 0 Answers

When to use OnSerializeNetworkView and RPC's 1 Answer

Help with Network Script. Game with multiple Maps. 2 Answers

Send a mesh via Network 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges