- Home /
Custom properties not updating as expected
Hi there. I'm currently working on a multiplayer FPS game.
I am using custom properties to keep track of kills and deaths. It works pretty well, but sometimes it updates one without the other, and I can't figure out why.
Here's how I create the PhotonHashTable:
PhotonHashTable customProperties;
//---
customProperties = new PhotonHashTable();
customProperties.Add("Kills", KillCount);
customProperties.Add("Deaths", DeathCount);
PhotonNetwork.player.SetCustomProperties(customProperties);
And here is how it is updated:
public void AddjustCurrentHealth(int adj, PhotonView viewID) //, PhotonMessageInfo info)
{
currentHealth += adj;
if(currentHealth <= 0)
{
Killed(viewID);
}
}
void AddKillToScore(PhotonView viewID)
{
if (viewID.isMine)
sb.UpdateCustomProperty("Kills", 1);
}
void Killed(PhotonView viewID)
{
AddKillToScore(viewID);
if(photonView.isMine)
{
sb.UpdateCustomProperty("Deaths", 1);
}
}
I would think, that when the method "Killed" is called, it would update Kill count on the one who got the kill as well as update Death count on the guy who died. And it does, but sometimes twice for one of the two and sometimes only for either the kill or the death, not both.
Any help is much appreciated. Thank you.
Answer by EX_Darius · Dec 05, 2013 at 02:58 PM
I think your problem is caused by having 2 seporate methods passing the same variable/name into eachother. A way that possibly fixes your issue is fusing the void AddKillToScore and void Killed together ;
void Killed(photonView viewID)
{
if(viewID.isMine)
{
sb.UpdateCustomProperty("kills",1);
}
if(photonView.isMine)
{
sb.UpdateCustomProperty("Deaths", 1);
}
}
Thank you very much for your reply. I tried what you said, and even realized my own way of doing it was pretty stupid. However it did not fix my issue.
I think I've found out why now: The AddjustCurrentHealth method is only called locally on each client, which apparently means that the other players do not always receive the currentHealth of their target. If the health of their target is then set to 10 or less (meaning that the next shot will kill them), and it doesn't update equally on both clients, player A would be able to kill player B more than once. Or player B would be able to die more than once.
This is also why it sometimes is able to update a lot of kills for only one death.
I thought I had fixed it by sending out the currentHealth of each player by RPC's to all others, whenever it has changed. But the issue is still occurring, so I'm once again at a loss about how to fix this.
I'm experiencing the exact same issue and am seeking a fix. I feel like it might have to do with the way Photon calls it but I'm not sure.
Your answer
Follow this Question
Related Questions
Load a scene after 3 deaths and show the score 2 Answers
kill counter 1 Answer