PlayerList.ActorNumber problem
Options
Good morning everyone,
I'm trying to create a multiplayer application for unity with PUN2.
This application is simple, first, you are into the lobby room and you create or join an existing room. Next, you join a waiting room with all the other players in this room.
My problem is this: Each player have a specified spawn point and this spawn point is attached to the Actor number of the player. For instance, for 4 players into the room, Player1 spawns at the spawn1, Player2 spawns at the spawn2 etc... If one player leaves the room, I want the next player to spawn at the position of the previous player. For instance, if 1,2,3 and 4 are present into the room and 2 leaves, I want the new player who spawns into the waiting room to becomes the player2 and not the player5.
I used the following property "PhotonNetwork.PlayerList[i].ActorNumber" in order to recover the actor number of the player. However, when I use this code I obtain [1,3,4,5] into the room instead of [1,2,3,4] when a player leave the room.
Does someone have an idea for helping me, please?
Best regards,
Axel
I'm trying to create a multiplayer application for unity with PUN2.
This application is simple, first, you are into the lobby room and you create or join an existing room. Next, you join a waiting room with all the other players in this room.
My problem is this: Each player have a specified spawn point and this spawn point is attached to the Actor number of the player. For instance, for 4 players into the room, Player1 spawns at the spawn1, Player2 spawns at the spawn2 etc... If one player leaves the room, I want the next player to spawn at the position of the previous player. For instance, if 1,2,3 and 4 are present into the room and 2 leaves, I want the new player who spawns into the waiting room to becomes the player2 and not the player5.
I used the following property "PhotonNetwork.PlayerList[i].ActorNumber" in order to recover the actor number of the player. However, when I use this code I obtain [1,3,4,5] into the room instead of [1,2,3,4] when a player leave the room.
Does someone have an idea for helping me, please?
Best regards,
Axel
0
Comments
-
Hi @Axel,
Thank you for choosing Photon!
You have two options:
- use the index of the PhotonNetwork.PlayerList array + 1: order may not be guaranteed.
- use PlayerNumbering utility script to have a PlayerNumber per player other than ActorNumber: add "Assets\Photon\PhotonUnityNetworking\UtilityScripts\PhotonPlayer\PlayerNumbering.cs" to the scene and then after joining get player number usingplayer.GetPlayerNumber()
.0 -
Hi @JohnTube ,
Thank you for your answer.
I saw in another topic that the actor number is reinitialised when a player is left (https://forum.unity.com/threads/photon-unity-joining-a-room-with-game-in-progress.564043/). But for my part, it is not the case. So the player Actor number is not free when a player leaves the room? Not a solution to free this space?
I'm trying to use the GetPlayerNumber property but I need to do a SetPlayerNumber before no?
Best regards,
Axel0 -
Hi @Axel,I saw in another topic that the actor number is reinitialised when a player is left (https://forum.unity.com/threads/photon-unity-joining-a-room-with-game-in-progress.564043/). But for my part, it is not the case. So the player Actor number is not free when a player leaves the room? Not a solution to free this space?I think there is a misunderstanding. An actor number is never reset, never freed, never recycled, never reclaimed and can overflow and go beyond MaxPlayers. You are probably mistaking it for the PlayerNumber.I'm trying to use the GetPlayerNumber property but I need to do a SetPlayerNumber before no?No there is no need to explicitly set the player number as it is done for you.
0 -
Hi @JohnTube ,
Thank you again for helping me.
Have you an example of how using the player Number?
For my part, the number of my player is -1 but I never call OnPlayerNumberingChanged.
Moreover, if you have an example of how to use it when a player leave for recovering his player number and use it if a new player arrives into the room.
Best regards,
Axel0 -
Hi @Axel,
In case you missed it, I explained the differences between Actor Number vs. Player Number here.
In PUN2, Asteroids and Cockpit demos use the PlayerNumbering utility script.For my part, the number of my player is -1How and when do you get this? after joining the room?I never call OnPlayerNumberingChanged.You don't need to explicitly callOnPlayerNumberingChanged
. It's an event you subscribe to when a player number is set or changed so you are informed for example to refresh UI.0 -
Hi @JohnTube,
Thank you again for your answer,
I see the Asteroid demo and the use of the GetPlayerNumber property. But my case is not present into this demo and I still recovering the player actor and not the player number.
When a player is initialised of left, I send an RPC message to the other players.
In my case, I have [1,2,3,4] in the room. When the player 2 Leaves, if another player enters into the room I obtain [1,3,4,5] (even with the Get player number) but I want [1,2,3,4]. So I have to change the player number no?
Best regards,
Axel0 -
Hi @JohnTube
In fact, I indicate the maximum number of players when I create the room and it's work correctly because if I indicate 2, only 1 other player can join the room.
For the test is a code like that:private void Start() { PlayerNumbering.OnPlayerNumberingChanged += OnPlayerNumberingChanged; } private void OnPlayerNumberingChanged() { foreach (Player p in PhotonNetwork.PlayerList) { Debug.Log("Player " + p.NickName + " with the number " + p.GetPlayerNumber()); } }
In this case, I can have in the console "Player Player2 with the number 5"
Best regards,
Axel0 -
Moreover, I need to have the player index to initialise the player at the good spawn.
With the following command, I instantiate the player at the good spawn.
PhotonNetwork.Instantiate(prefabOperator.name, SpawnPoint[playerInfo.SpawnIndex()].position, SpawnPoint[playerInfo.SpawnIndex()].rotation);
It's work correctly untill a player leave the room because one spawn player is missing.
hence my problem is to re use the player index of one player who is left.
Thanks by advance,
Axel0 -
Hi @JohnTube
It is possible to have a PlayerList without beeing inside the room?
Let me explain, I want to check the name of the player inside of the room and If the name already exists, the user cannot join the room with the same username. So I have to check it before to enter the room.
My problem is I never use the Room property because I use the RoomInfo property.public RoomInfo RoomInfo { get; private set; } /// <summary> /// Join a room as a user. /// </summary> public void JoinRoom() { /// Check if the player name already exist PhotonNetwork.NickName = RoomJoinController.join.userNameInput.text; PlayerPrefs.SetString("username", RoomJoinController.join.userNameInput.text); PhotonNetwork.JoinRoom(roomNameText.text); } /// <summary> /// Allow to synchronise the room information for the join panel. /// </summary> /// <param name="roomInfo"> Room inforoamtion </param> public void SetRoomInfo(RoomInfo roomInfo) { RoomInfo = roomInfo; roomNameText.text = roomInfo.Name; usersText.text = roomInfo.PlayerCount + "/" + RoomInfo.MaxPlayers; }
Do you have any idea about how I can do? Because in other cases I will have a problem with my player index if 2 people have the same player name.
Best regards,
Axel0 -
Hi @JohnTube
I use PUN2 with the unity package.
Yes, when player entering or joining a room they enter the username (PhotonNetwork.nickname). When the player arrive into the room, the other player can see the username of each player.
It is not possible to use the RoomInfo to create the Room? I see in the Room property that it is possible to have the list of players inside this room. So is not possible to recover the room.players information before to join the room ?
Best regards,
Axel0 -
So is not possible to recover the room.players information before to join the room ?Yes this is not possible.0
-
It is to bad, it is possible to count the number of player present in all the room but it is not possible to access to these players.JohnTube said:So is not possible to recover the room.players information before to join the room ?Yes this is not possible.
Thank you for your answer.
Axel
0