Get player number in room with ViewID

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.

Get player number in room with ViewID

MomasVII
2020-08-28 07:25:15

I have this code...

other.gameObject.GetComponent<PhotonView>().ViewID

Assuming PUN has a reliable list of players that does not change and can be traversed I want to find out what number in that list they are, if that makes sense.

So I have
Player1 VIEWID: 1001
Player2 VIEWID: 2001
Player3 VIEWID: 4001
Player4 VIEWID: 5001

I want to use the ViewID to find out that ViewID 4001 is 3rd in that list. I hope that all makes sense and is easily possible.

Thanks

Comments

JohnTube
2020-08-28 11:14:08

Hi @MomasVII,

Thank you for choosing Photon!

As explained here, the PhotonView ViewID is obtained using the actor number of the actor who instantiated/created it.
PhotonView.CreatorActorNr will give you the actor number.
The creator can be 0 if it's a room object.
The creator can leave the room or be inactive.

However you should be aware of the difference between actor number and player index in the room.

Back to top