Search Unity

Sending RPC's from a GameObject to another

Discussion in 'Multiplayer' started by GD-Darren, Dec 11, 2013.

  1. GD-Darren

    GD-Darren

    Joined:
    Jan 12, 2013
    Posts:
    53
    Hi, I have 2 gameobjects in my scene which are different, ClientHandler and ServerHandler.

    Client Handler has a ClientLogin script and ServerHandler has a ServerLogin script among other things.

    What ClientLogin does is get the data from the Login GUI and sends it to the server for authentication, if it is authenticated, ClientLogin needs to also send an RPC which is on ServerLogin the character that the client chose after logging in. Than ServerLogin handles the instantiate of the chosen character.

    GameObjects are also static (not instantiated at runtime, they are there before the play button is pressed), and I tried to set their network viewID to the same but it won't let me. I also tried to make 2 seperate scenes (client, server) and have the handlers on each witht he same network view id but it didn't work too.

    Would like to keep this architecture if possible, but if you can't think of a way to make this work, I would like to hear good alternatives.
     
  2. GD-Darren

    GD-Darren

    Joined:
    Jan 12, 2013
    Posts:
    53
    Fixed this, the problems were:

    When I did a separate client and server scene with the viewId manually set the same, I was calling the RPC before the player connected to the server so the network view was not initialized and this crashed the client. Call RPC's after there is a connection between the client and server.

    If you want to make client and server the same scene (for faster development) you can have the client and server scripts on the same gameobject with the same network view and then when you are ready to separate them just do what I said above, give them same viewId's in the different scenes.
     
  3. StaticDelvar

    StaticDelvar

    Joined:
    Aug 1, 2013
    Posts:
    5
    i ran into the same issue and solved it the same way, having both server and client objects on the same GameObject.
    though in the server script i check if ( !Network.isServer ) then disable itself.
    this allows me to run the client and server at the same time ie hosting a local game.
    i just have to be careful how i name my RPCs as RPCs are called by name on the GameObject its possible to call the RPCs on all scripts.