Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Mar 06, 2020 at 11:52 PM by TheDarkVoid for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by TheDarkVoid · May 21, 2015 at 05:01 PM · networkingnetworkrpc

Is there a more flexible method of sending data over network than RPC?

I've asked a similar question before and got a "working" solution but it is not ideal and has it's limitations. I'm wondering if there's another way to send data over the network aside from RPC or perhaps a more powerful way of using RPC? Ideally I'd like to be able to send any object across the network. Right now I have a PlayerData object that I want to send to the server and other clients, this contains all the information about a player (name, level, avatar, etc) and it not be ideal to send this information individually. Any help would be appreciated but it'll need to be fairly efficient both in speed and data size. Thanks in advance!

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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by harleywinks · May 21, 2015 at 06:17 PM

Protobuf is a good way to send serialized objects over the wire.

Nice properties include fast serialization/deserialization, support on many platforms, good support for backwards/forwards compatibility

Here's a good quick start tutorial for protobuf in unity:

http://purdyjotut.blogspot.com/2013/10/using-protobuf-in-unity3d.html

Comment
Add comment · Show 7 · 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 TheDarkVoid · May 21, 2015 at 07:53 PM 0
Share

I'll check it out, It seems promising.

avatar image TheDarkVoid · May 21, 2015 at 10:15 PM 0
Share

This worked perfectly, thanks. Also didn't know that you can send byte arrays with RPC. Interesting that it isn't documented.

avatar image harleywinks · May 22, 2015 at 12:54 AM 1
Share

Glad that helped. One additional tip since it took me a bit to figure it out:

In Unity/C# impl of protobuf it's more straightforward to define your types using Attributes as opposed to having a protobuf message file and compiling from that.

The problem is that you can't add Attributes to Unity struct types that you problably want to use, like Vector3.

The way to get around this is to add the unity types manually to your build script.

I'm building my protobuf serializer dll from a Unity Editor script (as opposed to my types dll, which I build from $$anonymous$$onoDevelop).

The script looks like this:

    using UnityEngine;
     using ProtoBuf;
     using ProtoBuf.$$anonymous$$eta;
     using UnityEditor;
     
         public class BuildDLL
         {
             [$$anonymous$$enuItem("Tools/Beat That/Serialization/Build ProtoBuff dll")]
             public static void Build()
             {
                 var model = Type$$anonymous$$odel.Create();
     
                             // some unity types
     
                 model.Add(typeof($$anonymous$$eyframe), false).Add("time", "value", "inTangent", "outTangent");
                 model.Add(typeof(Vector3), false).Add("x", "y", "z");
     
                 // my custom types here
     
                 
                 model.AllowParseableTypes = true;
                 model.AutoAdd$$anonymous$$issingTypes = true;
                 
                 model.Compile("ProtoSerializer", "ProtoSerializer.dll");
             }
         }

avatar image TheDarkVoid · May 22, 2015 at 01:26 AM 0
Share

Oh, does this mean I can use this technique to serialize unity types like NetworkPlayer, because that'd be really useful. I've tried some techniques but I'm not able to reproduce the same object on the other end. I'll have to try this. Also, if it required to compile it into a DLL? I've been using it so far without compiling to a DLL.

avatar image Bunny83 · May 22, 2015 at 02:38 AM 1
Share

The NetworkPlayer is a struct with just one single integer field. However this field is internal:

 public struct NetworkPlayer
 {
     internal int index;
     //...
 }

ToString returns this index as string but there's no way (beside using reflection) to "set" this internal value. So if you want to serialize the value you have to use reflection.

I'm not sure if this value does work on all clients or if they have some kind of local representation. This needs some further testing ^^.

If you want to serializa a Networ$$anonymous$$ViewID "manually", it also is just a struct however with 3 integer fields (called a, b and c)

 public struct NetworkViewID
 {
     private int a;
     private int b;
     private int c;
     // ...
 }
Show more comments

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiplayer Scoreboard Problem. 1 Answer

RPC sync issues 0 Answers

Networking Unity can't get players on network to change each others variables. 0 Answers

RPC Call doesnt get called 2 Answers

How to send timestamp via RPC so it was relative to the receiver? 1 Answer


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