Possible fix for 'DoInstantiate re-defines a GameObject'

Options
Hi.

Using v1.26.1, with PhotonNetwork.autoCleanUpPlayerObjects set to false, I was receiving the following error in the case where a player leaves the room when a game is in progress (scene has player-instantiated objects), later re-joins that room, and then a game object is network-destroyed by another client via Destroy(GameObject).

DoInstantiate re-defines a GameObject. Destroying old entry! ...

I seem to have fixed it by changing a few lines starting at 2322 of NetworkingPeer as follows (original code commented out):
#region Old code
//Debug.LogError(string.Format("DoInstantiate re-defines a GameObject. Destroying old entry! New: '{0}' (instantiationID: {1}) Old: {3}. PhotonViews on old: {4}. instantiatedObjects.Count: {2}. PhotonNetwork.lastUsedViewSubId: {5} PhotonNetwork.lastUsedViewSubIdStatic: {6} this.photonViewList.Count {7}.)", go, instantiationId, this.instantiatedObjects.Count, knownGo, pvaInfo, PhotonNetwork.lastUsedViewSubId, PhotonNetwork.lastUsedViewSubIdStatic, this.photonViewList.Count));
////this.instantiatedObjects.Remove(instantiationId);   // TODO: check if simple remove is ok in all cases. Maybe better Destroy!?
//this.RemoveInstantiatedGO(knownGo, true);
#endregion

#region New code
Debug.LogWarning(string.Format("DoInstantiate re-defines a GameObject. Destroying old entry! New: '{0}' (instantiationID: {1}) Old: {3}. PhotonViews on old: {4}. instantiatedObjects.Count: {2}. PhotonNetwork.lastUsedViewSubId: {5} PhotonNetwork.lastUsedViewSubIdStatic: {6} this.photonViewList.Count {7}.)", go, instantiationId, this.instantiatedObjects.Count, knownGo, pvaInfo, PhotonNetwork.lastUsedViewSubId, PhotonNetwork.lastUsedViewSubIdStatic, this.photonViewList.Count));
if (knownGo != null)
{
	this.RemoveInstantiatedGO(knownGo, true);
}
this.instantiatedObjects.Remove(instantiationId);
#endregion

Has anyone else seen this happen? If so how did you fix it?

Devs, do you think a fix can make it into a release soon...?

Thanks!

Comments

  • Tobias
    Options
    Actually, PUN is currently not expected to support re-joining. When you try, the client becomes a new "player" with a new in-room ID.
    Are you trying to regain control of your previously created GameObjects?
  • In my case, I would like to allow a user to rejoin the room as an observer only, so he doesn't need to regain control of anything. What I'd like to happen is, if he leaves the room, anything he's instantiated remains, and those objects are simply no longer controlled by anyone. If he later re-joins the room, he should be able to see everything correctly, but not have control of any objects.
  • Tobias
    Options
    You could submit a small (!) repro project and guide how to reproduce the issue. Without the stacktrace of the exception and some context, we can't solve this specific case.
    If there is a fix, we can send you the updated code easily.
    Mail to: developer@exitgames.com please.