PhotonNetwork.PlayerList always returns null

Hey,
I am currently working on a game using PUN v2, the free version. Currently whenever I raise an event, as part of the content I want to send the Photon ID of the other player in the room (each room has a maximum of 2 people). In order to do this, I check the PhotonNetwork.PlayerListOthers[0].userId and send that. My program always returns a index out of range exception, even though I'm calling the object at index 0 and there should be at least 1 player in there. I made sure that I am connected to a room before trying to access this value and it still returns a null array.

The purpose of me sending the ID is to make sure that only the intended player can parse the received data.

So, how can I deal with this so that I can get the other players Id?

Also, is there a different way to target specific players other than interest groups. Preferably not RPC's either as I don't use photon views on my players. Something that would work using the photon ID. I read something about sending events to specific players, but could not find any documentation on this topic.

Comments

  • Instead of sending an Event to everyone, you can also send it to just a specific player. This is the best way to make sure only this player can read it. Check our RaiseEvent:
    https://doc.photonengine.com/en-us/pun/v2/gameplay/rpcsandraiseevent

    PhotonNetwork.PlayerListOthers may be null or simply empty. Make sure you only access it while in a room.
  • Do you mean by using target actors? If so, how do i see a list of the actors available, and match that list to the players in my room?
    Or is there something else I haven't noticed?

    Thanks for your help! Its much appreciated.
  • The target actors can be used, right. The Player class has the actorNumber field, which you can use as target. When another player is in the room, the PlayerListOthers should be setup accordingly.

    I might be missing something but in a one vs one game, you don't really need to target anything.