- Home /
Persisting NetworkView across Scene change does not work
I have two scenes set-up as follows:
Scene A |_ ObjectA |_NetworkView (pointing at ScriptA) |_ScriptA
Scene B | ObjectB | NetworkView (pointing at ScriptB) |_ ScriptB
In Scene A I call Object.DontDestroyOnLoad(ObjectA). This prevents the object from being destroyed when I transition to Scene B.
Using ObjectA.networkView.RPC("SomeMethod", RPCMode.Others, params) correctly calls the RPC method on all networked clients.
I then transition to scene B and end up with the following set-up:
Scene B |_ Object A |_NetworkView (pointing at Script A) |_Script A |_ Object B |_ NetworkView (pointing at Script B) |_ Script B
Using ObjectA.networkView.RPC(...) still works.
Using ObjectB.networkView.RPC(...) does not work giving the error "RPC call failed because the function 'ObjectBTest' does not exist in any script attached to 'ObjectA'
If I load straight in to Scene B (so I don't end up with ObjectA) it works correctly.
It looks like Unity3D isn't ensuring unique NetworkViewIDs across scene changes.
I found the following bug that describes the same problem https://fogbugz.unity3d.com/default.asp?288477_235rid2h but I can't see what the resolution was.
Am I doing something wrong or do I have to work around this?
Possible solutions I've come across:
Splitting the object in two parts, the persisted object and a dummy object containing the networkview. The dummy object handles all RPCs (with the scene allocated NetworkViewID) and forwards them on to the persisted object.
Having a master object, persisted across scenes, that allocates all NetworkViewIDs to the server and the clients. Quite a pain to synchronise.
Answer by maraoz · Dec 24, 2012 at 08:43 PM
Found this:
The whole idea behind SetLevelPrefix is to differentiate NetworkViewIDs defined in different scenes. When you put a Network View in a scene, it's automatically attributed a View ID. But this View ID is guaranteed to be unique only in this very scene, not in your whole project. So you may end up having the same ViewID in different NetworkViews if you load scenes with LoadLevelAdditive or mark gameObjects with DontDestroyOnLoad. When this happens, RPCs to one may land in the other, and you'll be in for a lot of pain.
So maybe the solution is to use Network.SetLevelPrefix()
Your answer
![](https://koobas.hobune.stream/wayback/20220613085014im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiplayer Flashlight Issue 1 Answer
View ID AllocatedID: ### not found during lookup. Strange behaviour may occur 0 Answers
How to send UDP updates form server to each Client? 0 Answers
why if i destroy gameobject in 1st player and the other player is not? 0 Answers
State synchronization non-functional after mode change? 0 Answers