Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    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:
    274
    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:
    474
    that's a really handy tip for checking if you have a connection! thx
     
  6. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    474
    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,824
    This question asked a decade ago was for the previous networking API, not Unet.
     
  8. Fattie

    Fattie

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