Photon Networking - What function(s) are called when a player (not me) is spawned?

I’m trying to make a system to place a player’s name above them when they spawn. I have PhotonNetwork.owner for their name, the only problem is the most efficient way to update their name. Using something like:

somePlayerThatIGrabbedInAForeachLoop.TextMesh.text = PhotonNetwork.owner;

that would work, but since it’s in update, that seems a little inefficient. I’d prefer to have one function like void UpdatePlayerNames() where it just uses a foreach loop to grab all players and updates all their names so when a player joins or a player changes their names it will update all names (which isn’t a big deal if it does them all, not just the one that changed). Anyone got such function that is called when a player joins the lobby/game/server? THanks

2 Answers

2

Edit : https://doc-api.photonengine.com/en/pun/current/class_photon_network.html


The best thing to do is check the PDF that comes with the package. Here are some common functions called by Photon :

//  Photon Auto Called Functions
//  ----------------------------------------------------------------------------------------------


// OnJoinedLobby() - called when the Photon Network is connected to with ConnectUsingSettings
function OnJoinedLobby() 
{
	Debug.Log( "OnJoinedLobby() : Hey, You're in a Lobby ! " + PhotonNetwork.PhotonServerSettings.ServerAddress );
}


// called when a room is created by the player
function OnCreatedRoom()
{
	Debug.Log( "OnCreatedRoom() : You Have Created a Room : " + PhotonNetwork.room.name );
}


// called when a room is joined by the player
function OnJoinedRoom()
{
	Debug.Log( "OnJoinedRoom() : You Have Joined a Room : " + PhotonNetwork.room.name );
}


// OnPhotonRandomJoinFailed() - called when JoinRandomRoom() fails, no rooms available
function OnPhotonRandomJoinFailed()
{
	Debug.Log( "OnPhotonRandomJoinFailed() : No existing rooms ...." );
}


function OnPhotonPlayerDisconnected( other : PhotonPlayer )
{
	Debug.Log( "OnPhotonPlayerDisconnected() " + other.name ); // seen when other disconnects
}


function OnConnectedToMaster()
{
	Debug.Log( "OnConnectedToMaster()" ); // havn't seen this yet
}


function OnMasterClientSwitched() // definitely seen when the host drops out, not sure if it's when becoming master or just when switching
{
	Debug.Log( "OnMasterClientSwitched()" );
	
	if ( PhotonNetwork.isMasterClient ) 
	{
		Debug.Log( "isMasterClient " + PhotonNetwork.isMasterClient ); // called before OnPhotonPlayerDisconnected
	}
}


function OnPhotonPlayerConnected( other : PhotonPlayer )
{
	Debug.Log( "OnPhotonPlayerConnected() " + other.name ); // not seen if you're the player connecting
}

Thanks, this really helped! On line 33 you said OnPhotonPlayerDisconnected(). I wonder if there's one for OnPhotonPlayerConnected().

–

Yep, line 56 (not seen if you're the player connecting). Sorry for the poor layout, this was a quick copy and edit from my first Photon project. I'm sure there's more listed in the PDF, but these are the ones I use the most.

–

You are just a life-saver! Thanks!

–

Link is dead!

–

Try working with PhotonTarget.AllBuffered, see if that helps, I believe creating a public void, followed bby some kind of if statement may work

That's what I'm thinking, I didn't want to have to constantly check to see if someone joined, and I just didn't know if there was already a function that is called by Photon when someone joins.

–