OnPlayerEnteredRoom Not Working?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

OnPlayerEnteredRoom Not Working?

samdaman93
2021-11-27 03:28:15

Hello,

I'm trying to make a player card for each player that joins a lobby. The code looks like this.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Photon.Pun;

using Photon.Realtime;

public class gameManagerScript : MonoBehaviourPunCallbacks

{

enum gameState {Lobby, Intro, Nighttime, Voting, Reveal}

gameState currentGameState;

int playersInRoom = 0;

// Start is called before the first frame update

void Start()

{

currentGameState = gameState.Lobby;

}

public override void OnPlayerEnteredRoom(Player newPlayer)

{

Debug.Log("triggers on player enter");

GameObject playerCard = PhotonNetwork.Instantiate("PlayerPrefab", new Vector3(0, 0, 0), Quaternion.identity);

playerCard.transform.parent = GameObject.Find("Lobby Canvas").transform;

playerCard.transform.localPosition = new Vector3(-800, 400, 0);

playersInRoom += 1;

Debug.Log(playersInRoom.ToString());

}

public override void OnJoinedRoom()

{

Debug.Log("triggers on joined room");

GameObject playerCard = PhotonNetwork.Instantiate("PlayerPrefab", new Vector3(0, 0, 0), Quaternion.identity);

playerCard.transform.parent = GameObject.Find("Lobby Canvas").transform;

playerCard.transform.localPosition = new Vector3(-800, 400, 0);

playersInRoom += 1;

Debug.Log(playersInRoom.ToString());

}

OnPlayerEnteredRoom does not call, but onJoinedRoom does. I may be not fully understanding how all of this works, but does onJoinedRoom only call because I'm running multiple builds from the same computer i.e a local connection? would this change if I was running this across the internet?

Additionally with onJoinedRoom how would I get the players nickname so that I could set some text in the lobby for that players nickname. I'm very new so all help is welcomed!

Cheers,

Comments

omid3232
2021-11-29 08:18:28

hey bro , i answer based on my self experience , if you have photon view component on that game object which include this script, connection callbacks won't work ,so i guess if you check this and remove photon view or put this script on another gameobject with out photon view component it will be called. i had the same problem and i found solution by my self, tell me if it solved your problem :)

Back to top