Best practices: when to use PhotonNetwork.isMasterClient vs photonView.isMine?

Options
I'm fairly new to game networking, and I was wondering when it was more appropriate to run code on the master client or when the view is 'mine'.

Currently, I'm using isMasterClient on Start and Update methods for enemy AI. I also am using it to instantiate scene objects like enemies.

I ran into some issues though when I tried to destroy the enemies ONLY on the masterClient, and ultimately changed my EnemyHealth script to destroy when the view is 'mine'.

So I thought I'd ask here: When is it most appropriate to use the isMasterClient vs isMine?

Comments

  • Hi @looneygag,

    if you have an object with an attached PhotonView component, you can always use its isMine condition. The isMasterClient condition does not require an attached PhotonView component, instead you can basically use this condition 'everywhere' (else), for example for using certain game events (e.g. RaiseEvent).

    Currently, I'm using isMasterClient on Start and Update methods for enemy AI. I also am using it to instantiate scene objects like enemies.


    Since only the MasterClient can instantiate scene objects, you are fine with checking the isMasterClient condition for Instantiation. Since a scene object requires an attached PhotonView component, you can use its isMine condition for updating the object.

    I ran into some issues though when I tried to destroy the enemies ONLY on the masterClient, and ultimately changed my EnemyHealth script to destroy when the view is 'mine'.


    What exactly do you mean by "destroy the enemies ONLY on the masterClient"? Do you want to destroy the objects just for the MasterClient (objects remain on other clients) or do you only use the MasterClient to destroy the objects? In the first case you either have to use Manual Instantiation or instantiate those objects just for certain Interest Groups. In the second case, scene objects can only be removed by either the owner or the MasterClient.