Setting Custom player properties for a player who is in background from other players

Hi, We use ReconnectAndRejoin with PlayerTtl. Its a FPS game. So when a player goes to background. We want other players to still see him and be able to shoot and kill (in order to avoid exploit).

For this we update players properties from other players. It works perfectly and properties are being updated on all clients. But when this player comes to foreground, after ReconnectAndRejoin he receives old values same as when he had gone to background in OnPhotonPlayerPropertiesChanged callback. We have a workaround to solve this by setting his latest properties through RPC from master client.

Is there a reason for this behaviour? I think photon is caching player properties in separate location and when this player comes to foreground these cached values are returned instead of latest values.

Comments

  • Hi @avinashpdy (or @avinash ;))

    It is possible to set custom properties of inactive actors.
    There is no reason for any player to have outdated properties.
    The question is how are you doing this in PUN?
  • edited August 9
    Hey @JohnTube , In our game players set their own player properties in case of damage or any other event.When a player becomes InActive, we check if target player is InActive then shooter sets inActive players properties. Below is the sample code

    if (PhotonNetwork.player.ID == killerID && targetPlayerPhotonView.owner.IsInactive) { targetPlayerPhotonView.owner.SetHealth((int)m_currentHitPoints); targetPlayerPhotonView.owner.SetArmorPoints((int)m_currentArmorPoints); }

    Here targetPlayerPhotonView.owner is the one who has gone InActive. This code works perfectly and these properties are reflected on all other active clients. Its just when InActive player comes online (becomes active). PUN calls OnPhotonPlayerPropertiesChanged with old values on all clients. All values are reset to the one when he went offline.
  • It seems PUN resends locally cached player properties on a rejoin which overwrites and kind of reverts to old outdated ones.
    We will look into it.
    If it's a roadblock for you send an email.
    Feel free to dig into the code yourself of course.
  • JohnTube said:

    It seems PUN resends locally cached player properties on a rejoin which overwrites and kind of reverts to old outdated ones.
    We will look into it.
    If it's a roadblock for you send an email.
    Feel free to dig into the code yourself of course.

    Please let me know whenever you have any update on it, . We have implemented a workaround using RPC. But thats not a good solution as we had to do some hard coded checks for rejoin. If we get updated properties from PUN, it will be seamless.

    If the values are cached locally, i will go through PUN code and see if it can be fixed on client side plugin.

    Thanks for your response.
  • JohnTubeJohnTube mod
    edited August 13
    In "NetworkingPeer.cs" try replacing ReconnectAndRejoin() with this:
    /// <summary>
        /// Can be used to return to a room quickly, by directly reconnecting to a game server to rejoin a room.
        /// </summary>
        /// <returns>False, if the conditions are not met. Then, this client does not attempt the ReconnectAndRejoin.</returns>
        public bool ReconnectAndRejoin()
        {
            if (this.AuthValues == null)
            {
                Debug.LogWarning("ReconnectAndRejoin() with AuthValues == null is not correct!");
                this.AuthValues = new AuthenticationValues();
            }
            this.AuthValues.Token = this.tokenCache;
    
            if (!string.IsNullOrEmpty(this.GameServerAddress) && this.enterRoomParamsCache != null)
            {
                this.lastJoinType = JoinType.JoinRoom;
                this.enterRoomParamsCache.RejoinOnly = true;
                this.enterRoomParamsCache.PlayerProperties = null;
                return this.Connect(this.GameServerAddress, ServerConnection.GameServer);
            }
    
            return false;
        }
    Let me know if this fixes it for you.

    (only one line added: this.enterRoomParamsCache.PlayerProperties = null;)
  • @JohnTube Thanks for the fix. It did work.
Sign In or Register to comment.