When a player leaves the enemies leave with him

Options
My enemies are only appearing for all players when I use (PhotonNetworking.Instantiate) and the enemy already contains (PhotonView) but when a player leaves the room the enemies that were born leave with him, and if a player enters the room after the birth Of the enemies, the enemies do not appear, is there any script for me to use on the enemy in Update? Because I think (photon view) is not making a difference in my prefab


Comments

  • Hi @TyHover,

    but when a player leaves the room the enemies that were born leave with him


    This is a normal behaviour to keep rooms clean. You can use PhotonNetwork.autoCleanUpPlayerObjects = false; in order to keep instantiated prefabs in the scene when a client leaves the game. This however keeps the player's instantiated character in the scene, too, so you would have to remove this manually. You can read more about this on the Lifetime of Networked Objects section of the Instantiation Guide. There is also another way mentioned by using Scene Objects. These however can only be instantiated by the MasterClient.
  • TyHover
    Options
    Thanks, But the other question, when there is already a player in the room and already the enemies were born when another player enters he does not see the enemies that were already born only if he has in the room at the moment they are born, I tried to use it to instantiate the enemy (InstantiateSceneObject), but it did not result in anything.
  • TyHover
    Options
    :/
    )=
  • TyHover
    Options
    help
  • Do you load another scene before or after the first client instantiated those objects and furthermore do you have PhotonNetwork.automaticallySyncScene set to true? This can cause the behaviour you have mentioned.

    When using PhotonNetwork.InstantiateSceneObject(...) please also note, that only the MasterClient can actually instantiate scene objects as mentioned here.
  • TyHover
    TyHover
    edited April 2017
    Options
    [PunRPC]
    		public static Transform Spawn(Transform prefab, Vector3 pos, Quaternion rot)
            {
    
                if (!PoolManager.Pools.ContainsKey(poolName))
                    (new GameObject(poolName)).AddComponent<SpawnPool>();
    
                return PoolManager.Pools[poolName].Spawn(prefab, pos, rot);
    
    			PhotonNetwork.automaticallySyncScene = true;
    			Transform t = PhotonNetwork.InstantiateSceneObject(prefab.name,pos,rot,0,null).transform;
    
    			return t;
    			//return (Transform)Object.Instantiate(prefab, pos, rot);
    
            }
  • TyHover
    Options
    :/
    '-'
  • TyHover
    Options
    :/
    '-'
  • TyHover
    Options
    help
  • TyHover
    TyHover
    edited May 2017
    Options

    :/
    '-'
  • TyHover
    Options
    :/
    '-'
  • [Deleted User]
    Options
    What is
    return PoolManager.Pools[poolName].Spawn(prefab, pos, rot);
    actually doing? What's inside the Spawn() function? And do you need the return statement at all?

    From the code snippet above I would say, that PhotonNetwork.InstantiateSceneObject(...) is never called in this function, which would be a different problem from the one you have originally described.
  • TyHover
    Options
    I have a problem, that when a player starts the game the enemies are born, but when another player enters after the enemies are born he can not see the enemies, only if the two have at the moment of the enemy's birth, but I want the Enemy to stand on the two shelves.
  • TyHover
    Options
    :/
    '-'
  • TyHover
    Options
    :/
    '-'
  • TyHover
    Options
    :/
    '-'