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.
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.
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?
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.
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.
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.
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.
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’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.
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.
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 …
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.
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.