Double netWork id

Hello,

the following situation: A scene contains NetworkViews whose GameObjects are not destroyed on load. If a loaded scene also contains NetworkViews it is very likely, that some of them will have the same NetworkID Number, leading to all sorts of unwanted behaviour.

What is the best practice to prevent this? Add NetworkViews via script so the NetworkID is allocated at runtime?

You can do a networkView.viewID = Network.AllocateViewID() when the game starts, thus changing the scene ID to an allocated ID. You also need to use Network.SetLevelPrefix() to ensure the allocated view ID is not reused. You can set the prefix to 0, for example, when you start the game and allocate a view ID for your persistent object. Then increment the prefix before a new level is loaded. The prefix is applied to new allocated view IDs as they are allocated so the new level will not get any conflicts with your persistent objects view ID.

Keep in mind when doing dynamic view ID allocation of scene objects that new clients will have the old scene ID attached to the object. They need to be informed of the new allocated view ID, perhaps through a buffered RPC function.