(2018.3) PhotonView ID duplicate found

Hi all.
I am using same prefabs for multiplayer and single player. I got an object pool, which instantiates prefabs on start.
After upgrading to 2018.3 today (maybe it is somehow connected to the new prefab system), when I am launching singleplayer, I get errors "PhotonView ID duplicate found" on instantiating, and this error deletes my objects from pool. So my game becomes unplayable (i get missing references from my pool list).

As a workaround, I've added this to Awake() method in PhotonView.cs
if (!PhotonNetwork.IsConnected) this.ViewID = 0;

I'm not quite sure that this is the appropriate way to fix this. Can you please help me.
Multiplayer works just fine.

Comments

  • Hi @luvjungle,

    which version of PUN 2 do you use? If you have a version earlier than 2.5, please try updating to the latest version. In version 2.5 we added support for Unity 2018.3. Please let us know, if this solves the problem.
  • Version 2.5
    I tried to reimport it, but it didn't solve the problem.
  • I'm having the same issue. I am using a custom instantiation for several photonViews in the scene (including the player). It appears that upon GameObject.Instantiate, a default viewId is applied whether or not I use AllocateViewId. It is my understanding that instantiating a gameobject with photonView should not have a viewId other than zero until it is allocated by the player or MasterClient for scene objects.

    Everything worked fine prior to updating to 2018.3

    Please let me know when there is a fix for this.
  • luvjungleluvjungle
    edited December 2018
    Can you suggest a proper way of fixing it?
    Seems like when I instantiate a prefab with a viewID which is already occupied by another scene object (which was in scene from the start), my new game object destroys itself.

    added:
    Figured out a new fix for my case.
    Before instantiating I set my prefab game object to disabled state, and it's photon view id to 0, only then instantiate and allocate view id. It's not very performant wise, but I use pooler, so it all happens on start.
  • luvjungleluvjungle
    edited December 2018
    Ok, so my instantiating objects appears to have good IDs now.
    But my scene objects have a conflict. The ones that there from start. How come?

    Added:
    no, nothing helped. I still get duplicate view IDs. Seems like AllocateSceneViewID sometimes allocates wrong.
    Anyway, i guess i'll try to switch to PhotonNetwork.Instantiate and Photon's pool somehow
  • Still having this issue. Any updates? Mod who responded appears to have been deleted.
  • Same here.
    I switched to PhotonNetwork.Instantiate in multiplayer, but I still need
    if (!PhotonNetwork.IsConnected) this.ViewID = 0;
    in Awake() method in PhotonView.cs

    Don't want to keep it there, it's just not right.
    Hope that New Year hollidays are over and somebody will help with this issue
  • Hi,

    Are you using several scenes combines together?

    can you explain more about your modification? are you calling PhotonNetwork.Instantiate when you are indeed inside a room?

    Bye,

    Jean
  • TheSLAPTheSLAP
    edited January 11
    jeanfabre said:

    Hi,

    Are you using several scenes combines together?

    can you explain more about your modification? are you calling PhotonNetwork.Instantiate when you are indeed inside a room?

    Bye,

    Jean

    The problem is I'm not using PhotonNetwork.Instantiate at all. I'm using a manual instantiation method very similar to the one provided in the documentation:
    GameObject go = Instantiate( robotPlayerPrefab, spawnPoints[slot], Quaternion.Euler( 0, 180, 0 ) );
    PhotonView pv = go.GetComponent<PhotonView>();
    if ( PhotonNetwork.AllocateViewID( pv ) ) {
                        RaiseEventSpawnPlayerRobot( pv.ViewID );
                    }
                    else {
                        Debug.LogError( "Failed to allocate viewID. Destroying Robot" );
                        Destroy( go );
    }
    
    The OnEvent for RaiseEventSpawnPlayerRobot is sent only to Others simply instantiates the gameObject and sets the viewID to that which was allocated by client who spawned it.

    The issue is something with AllocateViewID I believe. It is assigning a duplicate ID despite that ID being already in the scene. I should note that the GameObject is instantiated from a serialized object on a monobehaviour if that matters.

    Everything works perfectly in 2018.2.

    To answer your questions, all calls are made within a room connected to PhotonNetwork in a single scene.
  • Hi,

    ok, I see. I'll have to discuss that internally, I'll get back to you.

    Bye,

    Jean
  • My problem is that when my pool creates gameObjects from prefabs, that have attached photonViews on them, their id's are being assigned to ones that already in use. So my gameObjects becomes destroyed on subj error.
    I use PhotonNetwork.Instantiate and custom pool for these objects for multiplayer now, and it helps, but in singleplayer I use same prefabs with standart Instantiate, so I have to use workaround which I wrote before.
    So i guess not only AllocateViewID is working incorrect, the whole allocation of ID's on Awake is not working properly (but maybe they uses same methods further, idk)
  • jeanfabrejeanfabre mod
    edited January 11
    Hi,

    yes, something is very fishy and we are currently debugging this, We are not sure yet if it's an issue within Unity or Pun.

    can you replace in the class "PhotonEditorUtils" the method IsPrefab() with this
    		public static bool IsPrefab(GameObject go)
    		{
    			#if UNITY_2018_3_OR_NEWER
    				return UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetPrefabStage(go) != null || EditorUtility.IsPersistent(go);
    			#else
    				return EditorUtility.IsPersistent(go);
    			#endif
    		}

    what is then your outcome when you run this case? and if it fails, can you try to simply edit the prefab just to set is dirty and then try again?

    Bye,

    Jean
  • Seems that it helped. Without setting prefabs dirty.
  • Hi,

    ok, thanks for your feedback, we are reviewing this change internally as well, and if all is green, it will make it in the next update.

    Bye,

    Jean
Sign In or Register to comment.