Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

can't send RPC function since no connection was started

Discussion in 'Multiplayer' started by llavigne, Mar 4, 2008.

  1. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    I am retrofitting my code with RPC calls and Unity isn't allowing me to call them when I'm not connected which is a problem as I am testing everything non connected. What's the work around ?
     
  2. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    I'm bumping this one before I start coding around this bug/limitation ...
    (aren't RPC folding back to sendmessage behavior when no network connection exist?)
     
  3. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    280
    Your can fire of RPCs when running as a server, which you can do when testing. If you are not connected to anything there is nothing to do with the RPC, hence the error. This is by design, it a Remote Procedure Call after all.
     
  4. jhaukur

    jhaukur

    Joined:
    May 21, 2012
    Posts:
    2
    I'm going to Necro this thread since I found it while googling solutions for a simular problem.

    A simple hack I quickly came up with was to simply create a server inside the script's awake function if we're neither client or server currently.

    This allows for simple non-networked scene testing of some functionality:

    Code (csharp):
    1. private void Awake ()
    2. {
    3.     // Create a fake server if we are neither client nor server so the RPC calls will function
    4.     if (!(Network.isServer || Network.isClient))
    5.     {
    6.     Network.InitializeServer(1, 25000, false);
    7.     }
    8. }
     
  5. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    that's a really handy tip for checking if you have a connection! thx
     
  6. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    That is indeed a great tip. Certainly during development.

    You're ultimately probably better to wait until the connection, with something like `OnPlayerConnected`,

    but again this is a great tip especially during development. Avoids the crash in the first few seconds while everything gets connected!
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This question asked a decade ago was for the previous networking API, not Unet.
     
  8. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Quite true Joe ! But this trick still works when you're using RPC functions in 2018 !