Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

Photonview SceneViewId bug on prefabs

$
0
0
Hello. Found a bug in PUN that got me scratching my head for a while.

The bug:
We have partially generated word that contains multiple Room prefabs that contain PhotonView component. Room also has child objects that contain PhotonView component. Rooms get instantiated via PhotonNetwork.Instantiate(). In my research, the nested prefabs structure did not make a difference.
Problem was that randomly some of the Instantiated Rooms would cause bunch of PhotonView ID duplicate found: and InvalidOperationException: Duplicate key errors, which made no sense, since by testing I noticed that only 4 rooms out of 44 was causing this issue.

By digging I found out that Unity had saved (probably on the runtime) the prefab's (unexposed) sceneViewId on the PhotonView component. This caused the PhotonView component to automatically change it's ViewID to this saved value in PhotonView.cs Awake() function.
By doing this, Photon will automatically force other objects with that ViewID to be destroyed, which in our case was core scene objects.

The fix:
Minor change to PhotonViewHandler.cs OnHierarchyChanged() function. Starting the line 63
Old:
if (view.ViewID != 0)
{
   view.ViewID = 0;
   EditorUtility.SetDirty(view);
}

With scene view zeroing
if (view.ViewID != 0 || view.sceneViewId != 0)
{
    view.ViewID = 0;
    view.sceneViewId = 0;
    EditorUtility.SetDirty(view);
}


Using versions
PUN 2.30
Unity 2019.4.13f1

Viewing all articles
Browse latest Browse all 8947

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>