• 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
0
Question by Aborup · Nov 25, 2012 at 11:13 PM · multiplayernetworkserverrpcclient

Networking RPC calls never sent to other clients

Hello,

I've been leaning up against the Unity scripting reference for networking lately, and I've set up a server and clients. The clients report they've successfully connected to the server every time, but none of the RPC calls make it out of the calling client and over to the other clients.

Here's my server initialization script: http://pastebin.com/q0hNRkXq

And here's my client's "connect to server" script, w$$anonymous$$ch sends two RPCs: http://pastebin.com/H2Wg6ZWc

Lastly there's the client-side script that handles incoming RPCs: http://pastebin.com/vzwMkSzn

My problem is: when sending RPCs with any other RPCMode's than RPCMode.All and RPCMode.AllBuffered, I see no result. That indicates that the RPC never reaches any of the other connected clients and the only receiver of the RPC is itself.

As I've been leaning up against the Unity scripting reference (http://docs.unity3d.com/Documentation/Components/NetworkReferenceGuide.html), why it doesn't work is greatly confusing to me - because I've done as the reference says, as far as I'm aware of.

Do I need some sort of RPC forwarding script on the server? Why can't two connected clients communicate when they're connected to the same server?

I'll greatly appreciate any attempted help!

Thank you very much

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

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

Answer by Bunny83 · Nov 25, 2012 at 11:21 PM

Of course that doesn't work because you only create your player object locally. RPCs are sent from an object's networkView to it's counterpart on another client. The NetworkViewID you allocate is valid on all clients, but it's not assigned to an object on the other clients. Therefore your RPCs you send are lost because there's no receiver.

The usual way is to either have a "communication object" in a scene and every peer loads t$$anonymous$$s scene. NetworkViews on scene objects automatically get a NetworkViewID w$$anonymous$$ch is the same on each client.

Another way is to use Network.Instantiate w$$anonymous$$ch takes care of instantiating th object locally as well as on all other clients. In addition it will sync the NetWorkViewID(s) w$$anonymous$$ch automatically gets allocated for the object.

I don't really like Network.Instantiate since it uses a buffered RPC w$$anonymous$$ch can't be removed that easy. I always use a communication object in a scene.

edit

I've made (another) very simple chat example script. Just create an empty GO in a scene and attach the script. It requires a NetworkView w$$anonymous$$ch should be automatically attached. Build your game and make sure the scene that contains the GameObject with the script, is the first one in the scenes list (in the build settings).

Start 2, 3 or most instantex of your game and make one the server. Start the server and connect the other clients to the server.

Comment
Add comment · Show 4 · 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 Aborup · Nov 26, 2012 at 12:18 AM 0
Share

Hi, thank you. I used Network.Instantiate(); first, but I had issues with it and it never worked properly AT ALL. I couldn't find anyone with simular issues through googling... So now I'm using RPCs. Do you think you can give more information on your "communication object" (perhaps upload some example code, or explain how to do it properly)? Thank you very much for your time and help!

avatar image Bunny83 · Nov 26, 2012 at 10:57 AM 0
Share

I don't have time, but the important thing is that every peer (clients and server) load the same scene. This scene should contain an emptyGO with a networkview. This networkview will get linked to all other connected clients automatically when they load this scene.

If i can find the time i will post a sample

avatar image Aborup · Nov 26, 2012 at 09:53 PM 0
Share

Thank you, I was helped by Zerot to make this work and it's now fully functional. I couldn't be happier!

avatar image Bunny83 · Nov 27, 2012 at 11:14 PM 0
Share

Just like to add that RPCs are automatically forwarded by the server to the right target. The main problem with RPCs is that the Unity API only provides context sensitive RPCs. So an RPc can only be send from a NetworkView from one client to a NetworkView on another client which has the same NetworkViewID.

Sending RPCs to all objects or something like that doesn't exist in the API. Unity however has something else internally which enables Network.Instantiate to work without a context object.

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

12 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

Related Questions

Server and Network no communication 1 Answer

Do i need to have 2 seperate apps communicating for server/client relationship? 2 Answers

Get RPC senders ID, or IP? 1 Answer

How to hide a started/full server 0 Answers

Player falls through plane/floor (Multiplayer) 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