Search Unity

Looking for RPC in the wrong networkview?

Discussion in 'Multiplayer' started by hogus, Sep 25, 2009.

  1. hogus

    hogus

    Joined:
    Jul 9, 2009
    Posts:
    145
    Hi,

    I have a gameObject called GameState that contains a GameStateScript and I've set the DontDestroyOnLoad property for the gamestate in this script's awake method.

    This GameState object lives in my "Init" level which is my entry point into the game.

    Now I've written a whole menu system that does saves, loads, or creation of network games.

    Once I load a level for a network game I want each client to report in on the OnLevelWasLoaded event.

    At this point I call an RPC

    Code (csharp):
    1.  
    2. networkView.RPC("NetworkPlayerLevelLoaded", RPCMode.Server, Network.player);
    3.  
    Which exists in the GameStateScript, and therefore I would expect it to look for this RPC in the networkView associated with the GameState object...

    But instead of trying to find this RPC on the network view belonging to my GameState object after the level load has completed, for some strange reason, it tries to find this RPC in a network view belonging to a completely different gameObject that happens to be created when I load the my first game level.

    It seems to just pick the first network view it can find, instead of using my GameState's networkview.

    Has anyone had this kind of problem before?
     
  2. hogus

    hogus

    Joined:
    Jul 9, 2009
    Posts:
    145
    Is it possible that my gamestate's network view is being re-constructed when a level loads, and that unity then just looks for the RPC in any random network view?
     
  3. hogus

    hogus

    Joined:
    Jul 9, 2009
    Posts:
    145
    Further tests reveal, that If I remove all other objects in my start level that contain a network view, that everything works again.

    So it seems that when the Level loads something odd is happening to any network views that are in non-destructable gameobjects.

    Its almost as if the reference to the network view is being lost, and Unity then scans through all existing views and just re-assigns the first one to the gameobject.
     
  4. Agrios

    Agrios

    Joined:
    Aug 21, 2009
    Posts:
    50
    This would be my experience as well.
    I think we have to know more about NetworkViews.
    How are they related to RPCs, what they have to observe, how many we need them and how to manage them.
     
  5. hogus

    hogus

    Joined:
    Jul 9, 2009
    Posts:
    145
    Hmmm... well lets see if anybody else has any thoughts on it. In my view this seems like a bug. If I set a gameObject not to be destroyed on level load, I would expect all attached components to survive intact.

    Unless someone else can give a valid reason why this shouldn't be the expected behavior I'll log it.

    In the meantime I'm going to instantiate a surrogate gameobject on every level to handle communications for my GameState.
     
  6. oxl

    oxl

    Joined:
    Nov 21, 2008
    Posts:
    325
    Hi,
    I had a similar problem, Unity tried to call an RPC function on the wrong GameObject. That drove me crazy , until I removed the NetworkViews, that were observing the scripts and re-added them. The error was gone.

    Don't know if that helps in your situation, though.

    --
    oxl
     
  7. ryan_scott

    ryan_scott

    Joined:
    Jun 12, 2009
    Posts:
    7
    I ran into this same problem and it would appear that the networking layer isn't taking into account objects with DontDestroyOnLoad called against them when allocating new NetworkViewIDs, so you end up with conflicts and it looking to the wrong component to try and call your RPC method.

    I wrote a sample project and posted a bug: http://fogbugz.unity3d.com/default.asp?287473_jhfojqus

    I'm not entirely sure if it's a bug or the way the system is designed, but at the very least some documentation about how view IDs are allocated would help.
     

    Attached Files:

  8. hogus

    hogus

    Joined:
    Jul 9, 2009
    Posts:
    145

    Attached Files:

  9. hogus

    hogus

    Joined:
    Jul 9, 2009
    Posts:
    145
    Well...

    Creating a surrogate gameobject to hold the network view for a non-destructible gameobject works well, and I've actually given it a bit of additional responsibility to justify it's existence.

    If I get around to it I might even get my GameState object to automatically instantiate it on Awake and OnLevelWasLoaded... but it actually works very well for me now.

    If I don't drop a GameSurrogate into a level I disable network play, so I can just ommit this when I want to do single-player games.
     
  10. Brad-Keys

    Brad-Keys

    Joined:
    May 1, 2006
    Posts:
    161
    This problem seems to still exist, though the bugs are now closed.
     
  11. Swift On Fire

    Swift On Fire

    Joined:
    May 24, 2012
    Posts:
    1
    Does this mean the Unity team does not intend to fix this issue?
     
  12. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    November 2012, and I confirm that this very exact problem still exists.
    We have to kill/recreate NetworkViews on persistent objects in any level loading (may it be additive or not ...), or their ID simply mess up and we end with RPC calls searching wrong networkViews.

    That's very unfortunate, because there couldn't be any more need for persistence across levels than for a network synchronization ...
     
    Last edited: Nov 7, 2012
  13. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
  14. atrakeur

    atrakeur

    Joined:
    Jun 14, 2011
    Posts:
    134
    Prefix is meant to avoid the engine to look for the wrong networkView when switching levels.
    Prefix just globally discard messages send with another prefix that the one unity is waiting for.

    You can use SetPrefix to avoid getting warning and unnecessarily viewID lookup, but you still have to resync all networks views each time a new level is loaded.

    I'm afraid the only solution to this issue is to switch from buildin networking to another network library.
     
  15. SaxiLamb

    SaxiLamb

    Joined:
    Sep 13, 2014
    Posts:
    1
    Not sure if the problem was exactly the same...But I had an issue where I was calling a movement RPC on my Client object to move my players character and it was throwing an error saying the Server object didn't contain the RPC.

    The Client object and Server object both had the ViewID 0 so I decided to see if the networkview only sends RPC calls to the network views of the same ID on the server. I put the player controller script onto the character prefab where I wanted the RPC to call and it worked. So my theory is that RPC calls are transmitted to objects with the same ViewID over the network and thats why I was getting an error Saying the RPC didn't exist. I'm not sure if this helps and I know this topic is two years old but if anybody else stumbles across it like I did. Hopefully this can be of some help to someone.