How to get a client ID?

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.

How to get a client ID?

lennart862
2017-08-04 01:43:21

A very simple question: I have a script on an instantiated game object and I want something like this:

public int GameObjectOwnerID;

void start()
{
GameObjectOwnerID = PhotonNetwork.player.id;
}

The player id is the same id you get if you receive an event by PhotonNetwork.RaiseEvent. If you receive the event you get the senderid which you can use for conditions etc... Thank you in advance!

Comments

[Deleted User]
2017-08-07 08:10:11

Hi @lennart862,

if this game object gets instantiated through PhotonNetwork.Instantiate, it has an attached PhotonView component. Using this you can get the ID you are looking for: GetComponent().ownerId

PhotonNetwork.player.ID only returns the ID of the local client, so using this would end in an unwanted behaviour.

Back to top