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! Your search result can be found below. Plus, we offer support via 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.

Locate Master Client GameObject using PhotonNetwork.IsMasterClient

JoãoVitor
2021-06-25 17:25:38

Hello everyone, i'm trying to find my masterClient using photon network, my software consists of instantiate a player at the scene and then find a script witch will save your gameobject if you are the masterClient then if you are not the master client you will only instantiate an sprite at masterClient canvas, but it's giving me a nullpointer when you are not the masterClient as masterClient activates twice.

those are both of my scripts

ps: sorry for my bad english.

script 1 : On Player prefab

script 2 : On scene

Thanks in advance !

Comments

hannahmontanna
2021-06-29 10:34:57

i think your code might be a little over-engineered for what you are going for!

Try using (PhotonNetwork.IsMasterClient) to check and get a bool if you are a master client....and PhotonNetwork.MasterClient to get a Photon.Realtime.Player object representing the player who is the master client (should always be player 0 (1) unless custom logic.

So there really is no reason to do and RPC for all that....

In start, just call like

If (PhotonNetwork.IsMasterClient)
{
gameObject.Tag = "MasterClient"
}
else
{
gameObject.Tag = "Scrub";
}

JoãoVitor
2021-06-29 12:52:42

Hey @hannahmontanna thank you for the reply ! , i still got the error message and the gameobject didin't change de tag, maybe is because i'm new in photon i still don't got it the right way to do that, i created a new script with less things like you said, here fallow my new script.

JoãoVitor
2021-06-29 16:02:15

*repost

Hey hannahmontanna thank you for the reply ! , i still got the error message and the gameobject didin't change de tag, maybe is because i'm new in photon i still don't got it the right way to do that, i created a new script with less things like you said here fallow my new script

if (PhotonNetwork.IsMasterClient)
{
transform.tag = "Master";

hannahmontanna
2021-06-29 16:23:31

Can I ask why you are trying to find the master client like this? You can message them directly at any time with built in photon remote procedure call and raise event?

JoãoVitor
2021-06-29 18:08:01

Hello again Hanna i happily come to inform i have managede to solve the problem ! :smile: , i was using like that because i need to find the master for each player and then do something to demostrate him as a master of the room, about the events i haven't masterded yet :( , but i'm still learning about events and photon 2.

here is my code, so basically for each player on their scene will found the master, if the master quit
probably i can just call this method again and its solved :)

about this way you mentioned you got any example ? or a link, i will love reading to try to improve

Thanks a lot !

hannahmontanna
2021-06-29 19:16:16

Hey, what I am saying, is you do no need to find the master, but if you did, you can ALWAYS find the master client via photo network.masterclient, even when the master client leaves, it is automatically switched via photon backend!!!!

hannahmontanna
2021-06-29 19:17:08

In any given room, the photon master client, regardless of what player is checking, will always be photo network.masterclient!!!

hannahmontanna
2021-06-29 19:18:45

And if you want to check a particular photon view, if it is master client, you can check
If (photonView.Owner == PhotonNetwork.MasterClient)

JoãoVitor
2021-06-30 11:09:30

hello hanna , thanks for the tips :) i'm going to use them

Back to top