Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

networkView, ID, RPCs

Discussion in 'Multiplayer' started by sriram, Sep 9, 2010.

  1. sriram

    sriram

    Joined:
    May 1, 2010
    Posts:
    13
    Im new to multiplayer with unity 3d, but yet i managed to make a small multiplayer game, but seriously i have lots of doubts about multi-player concepts. I wish someone could enlighten me about the following concepts/doubts, this could be useful for other beginners like me too in multiplayer gamming::

    1. What is networkView and what does viewID signify?
    2. How networkView and RPCs are linked?
    3. What is a "group" in networkView?
    4. Suppose i use a code like the following:
    Code (csharp):
    1.  
    2. //attached to object 1
    3. networkView.RPC("test",RPCMode.Server);
    4. ...
    5. ...
    6. @RPC
    7. function test()
    8. {
    9. //code here
    10. }
    11.  
    My question is, suppose i have many object clones with the above code attached, if one client calls the RPC to test(), how exactly test() of that particular object is invoked?? I mean that all the object clones have test() function, but how only that is invoked? viewID or something is sent along with each RPC??

    Please enlighten!
     
  2. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
    1. Network View is a component, THE component. Without him, no RPC and state synchronization. Each Network View has a Network View ID that makes him unique.

    2. RPC are like SendMessage, but for network. When you make a RPC call, the game object doing it should have a Network View. The Network View then looks for a game object with Network View with similar Network View ID in targeted players and ask it to execute the function.

    3. See it as a way to group communications : state synchronzations, RPC. You make enable and disable temporarily those groups. Someone else could tell you more, maybe.

    4. One function will be invoked, for each player you chose. So, in you write networkView.RPC ("test", RPCMode.Others), everyone except you will receive the RPC. Since your Network View has a View ID, others users will find their own game object with similar Network View ID, and execute "test".
     
  3. giancamati

    giancamati

    Joined:
    Aug 4, 2010
    Posts:
    518
    WOW thanks a lot, that's a very useful and handful help!
    I have a further question tho, is it possible to call an RPC belonging to another object with a different Network ID?

    Many Thanks,
    Giancarlo

     
  4. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
    I don't really understand the question but ...

    Any game object can "execute" a RPC call, you don't have to limit yourself in writing

    Code (csharp):
    1. networkView.RPC ("test", RPCMode.All):
    You can write :

    Code (csharp):
    1. var nView : NetworkView;
    2. nView.RPC ("test", RPCMode.All);
    Even if the Network View in nView is not on the same gameobject as this script.
     
  5. giancamati

    giancamati

    Joined:
    Aug 4, 2010
    Posts:
    518
    Thansk a lot! :)
    well my question comes as I have a client/server model for a chatline. Now,
    I have 3 obejcts:
    1) LoginOBJ (which links to login.js and chat.js)
    2) wwwmanager (which has its own script and has the datastructure which contains the list of 3D models in the scene).


    the problem I have is when ever a new clients connects I need to load the up-to-date scene. So I thought to make an RPC (onUpdateScene)function and put it in the wwwmanager. But, in the client (the script for the chat) when it gets connected I got an error as Chat script is connected to LoginObj which has no onUpdateScene function.

    Any suggestion?

    Many thanks.
    Giancarlo