Cant see players which are already joined.

Freel4tte
edited October 2011 in DotNet
I am making a multi player game and now I'm testing it with the Angry Bots Photon demo stripped down to the player model. I already made a login screen, a lobby and a level. When I host a game I join the level and run around and shoot into oblivion and I can see other players who join later then me. But every player who joins next cant see the players already connected before him.

Unity gives the error about Photon id's that are 1000 and over and that such PhotonVIew dont even exist. Is this the cause of the problem or is it something else. And how do I make this work?

Help is really appreciated and thanks in advance!

Comments

  • Hm, as much as I'd like to dive into debugging this, I can't. Once you modified the projects so heavily, we can't really support everyone.

    Most likely you modified some prefab or gameobject which had a script or PhotonView somewhere.
    You should probably take a look at the Viking Demo or at the Worker Demo. Both have just the essentials in and comparing those with your project might help you identify the broken spot.
  • Thanks for your reply! But generally speaking, what is wrong with wich script when players can't see each other?
  • you don't buffer the previous instantiations for example so newly connected players are not informed about players already in the game. Thats the most common error basically that leads to this.
  • Maybe you use GameObject.Instantiate() instead PhotonNetwork.Instantiate()? Then the views are not created on all clients.
  • dreamora wrote:
    you don't buffer the previous instantiations for example so newly connected players are not informed about players already in the game. Thats the most common error basically that leads to this.

    Sorry to be a pain in the ass, but where can I find these bufferings. I tried to look for myself but its kind of hard for me to understand it all. It's really important for me to get this fixed so that's why i'm asking so much. :?
    Thanks for your reply tough!
  • PhotonNetwork.Instantiate buffers it automatically, same goes for RPCs you send with xxxBuffered as PhotonTarget anything else is not buffered and new players won't know about it at all unless you resent the RPCs etc to them.
  • Again: Please check your code if you accidentally used GameObject.Instantiate() instead PhotonNetwork.Instantiate()?
    Then the views are not created on all clients and you don't see others.
    Buffering of instantiations is done for you. I just wanted to explain the background.
  • Tobias wrote:
    Again: Please check your code if you accidentally used GameObject.Instantiate() instead PhotonNetwork.Instantiate()?
    Then the views are not created on all clients and you don't see others.
    Buffering of instantiations is done for you. I just wanted to explain the background.

    I checked it and its PhotonNetwork.Instantiate
    GameObject GO =PhotonNetwork.Instantiate(playerPrefab, transform.position, Quaternion.identity, 0);
    
    Sorry for not answering your reply.
  • Hmm. Then I don't really see how this should happen.
    Could you provide a minimized package which shows the issue or attach the important code?
  • I don't understand the minimized package part, but I can add the Gamemanager code (I think it's the important code).
    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    
    public class GameManager : Photon.MonoBehaviour {
    	
    	public GUISkin skin;
    	public Transform playerPrefab;    
    	
    	public static Transform localPlayer;
        public static List<Transform> players = new List<Transform>();
    	
    	public static Transform GetClosestPlayer(Vector3 fromPos){
    
    		Transform close = null;
            float dist = -1;
            foreach (Transform tra in players)
            {
                if (tra == null)
                {
                    continue;
                }
                float thisD = Vector3.Distance(tra.position, fromPos);
                if (dist == -1 || thisD < dist)
                {
                    dist = thisD;
                    close = tra;
                }
            }
    		return close;
    	}
    
    
        public static void AddPlayer(Transform tra)
        {		
            players.Add(tra);		
        }
        public static void RemovePlayer(Transform tra)
        {
            players.Remove(tra);
        }
    
        void Awake ()
    	{
    		//PhotonNetwork.sendRateOnSerialize = 10;
    		//PhotonNetwork.logLevel = NetworkLogLevel.Full;
    		
            //Connect to the main photon server. This is the only IP and port we ever need to set(!)
    		if (!PhotonNetwork.connected || PhotonNetwork.room == null) {
    			PhotonNetwork.Connect("localhost", 5055, "AngryBots");
    			PhotonNetwork.JoinRoom("JoinARoom");
    		}
    
            PhotonNetwork.isMessageQueueRunning = true;
            //Spawn our local player
    		
            GameObject GO =PhotonNetwork.Instantiate(playerPrefab, transform.position, Quaternion.identity, 0);
        	localPlayer = GO.transform;
    		
    	}
        
        void OnGUI ()
    	{
    		GUI.skin = skin;
    		GameGUI ();
    		if (GUILayout.Button("Retry", GUILayout.Width(75)))
                PhotonNetwork.JoinRoom("JoinARoom");
    	}
    	
    	bool showDebug = false;
    	
    	void Update ()
    	{
    		
    		if (Input.GetKeyDown (KeyCode.Q))
    			showDebug = !showDebug;
    	
    		if (Input.GetKeyDown (KeyCode.Escape)) {
    			Application.Quit();
    		}	
    		
    	}
    
        /// <summary>
        /// Check if the game is allowed to click here (for starting FIRE etc.)
        /// </summary>
        /// <returns></returns>
        public static bool GameCanClickHere()
        {
         
            List<Rect> rects = new List<Rect>();
            rects.Add( new Rect(0,0,110,55));//Topleft Button
            rects.Add(new Rect(0, Screen.height-35, 275, 35));//Chat
    
            Vector2 pos = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
            foreach (Rect re in rects)
            {
                if (re.Contains(pos))
                    return false;
            }
            return true;
    
        }
    
        void GameGUI(){
    		GUILayout.Space(32);
            if (GUILayout.Button("Leave"))
            {
                PhotonNetwork.LeaveRoom();
                Application.LoadLevel(Application.loadedLevel+1);
            }
    		
    		
    		
    		if(showDebug){
    			GUILayout.Label("isMasterClient: "+PhotonNetwork.isMasterClient);
    			GUILayout.Label("Players: "+PhotonNetwork.playerList.Count);
    			GUILayout.Label ("Ping: " + PhotonNetwork.GetPing());			
    		}
    		
    	}
    
    }
    

    Hope this helps!
  • I have found the thing that made this happen. When I join a room, the Awake part in the GameManager scripts gets activated and Instantiates a playerprefab. But it Instantiates while the login scene is still loaded. So when the game scene is loaded the already Instantiated player is already spawned in the script, but nowhere to be seen in the scene.

    My recent solution was to use a GUI.Button to instantiate the playerprefab. I waited untill both players where in the game scene, then clicked the button and both where instantiated in both the players scene's.

    Thanks for all your help!
  • I have a similar problem. I managed to solved it by creating a GameManager handler and monitors each time a player enters a room. When someone does, it will "refresh" the instance of all players inside. This is similar to @Freel4tte's solution. You can use

    public override void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer)

    God bless and happy coding! :smile:
  • I use Photon PUN 2 btw.
    I know this thread is very old but maybe some newer viewers who are also having the sample problem could stumble upon this thread, so I'll just leave my answer here.

    :smile:
  • M4rCOS
    M4rCOS
    edited February 2020
    Hello! I had the same problem and I found out that I was loading my Play scene with SceneManager.LoadLevel instead of PhotonNetwork.LoadLevel.

    I know it's a dumb thing but it worked in my case.
    Perhaps someone else will be in the same situation so remember to check for this.

    Happy coding! :)
  • Llaarryy
    Llaarryy
    edited March 2021
    Hey @M4rCOS

    I guess you'll never see this but just in case I wanted to tell you that you just made my day. I was soo frustrated.
    Thank you so much, you're awesome!
  • @Freel4tte could you help explain how you fixed it as in showing the code maybe?

  • @DKReigns Was there anything to input within brackets after putting that or did it work alone?

  • @M4rCOS THANK YOU!!!! I was so lost. I'm glad it only took me an hour and a half to find this