• 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
Question by inventonater · Dec 13, 2010 at 10:23 AM · multiplayernetworkrpcrts

RPC Parameter Optimization

Hey everyone, I am building a multiplayer RTS style game which needs to keep hundreds of characters up to date over the network. I use RPC calls for everything so I can be very selective about what needs to be updated. Things are working pretty well so far, but I have a few questions about optimizing RPC calls.

I know Unity is very smart, and I was wondering if it does anything behind the scenes to compress int values? For example, I have a bunch of values which I know will never exceed 10. So I do something like...

void ReplicateAllValues( int valueA, int valueB, int valueC )
{
  int valueSentWithRPC = valueA + valueB*10 + valueC*100 ;
  networkView.RPC("ReceiveAllValues", RPCMode.All, valueSentWithRPC );
}
[RPC]
void ReceiveAllValues( int valueFromRPC )
{
  int valueA = valueSentWithRPC % 10 ;
  int valueB = (valueSentWithRPC % 100) /10 ;
  int valueC = (valueSentWithRPC % 1000) /100;
}

Is this worth my time? Or does Unity do compression behind the scenes that makes this silly?

Secondly, how much bandwidth overhead is there for each RPC call? If I make 100 calls to a function which takes a single int, how much worse is that than calling a single function which takes 100 parameters?

Finally, am I correct in thinking that if I do not declare a NetworkMessageInfo parameter in my [RPC] function that bandwidth will be saved? Or is that information always sent reguardless?

Thanks

Comment
user-12554 (google)

People who like this

1 Show 0
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

· Add your reply
  • Sort: 
avatar image

Answer by PaulUsul · Feb 24, 2012 at 07:04 PM

Hi, this is a really old question but thought I'd give it a shot.

You can send byte arrays, which is a really good optimization in your case where you know that the values never exceed 10, so you can call one rpc with one byte array[100].

if you really want to optimize your bandwidth, you can split the byte in 2. So you have to 4 bits that can represent 0-15. This can also be done with a int splitting it to 8 4 bits if you often have bigger updates and want to minimize bandwidth, of course this comes at a minor processor cost.

Comment

People who like this

0 Show 0 · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

When connected to a server, can other players access my static variables and/or public variables? 2 Answers

Photon Networking: RPC call doesn't work over other clients 0 Answers

Sending info to/from different networkViews 1 Answer

Networking RPC calls never sent to other clients 1 Answer

RPC call on other scene,NetworkView RPCs in other scene, 0 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