Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jellezilla · Dec 05, 2013 at 01:28 PM · scoredeathhashtablekills

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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);
    }
 }

 
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jellezilla · Dec 08, 2013 at 04:44 PM 0
Share

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.

avatar image nonlin · Feb 03, 2015 at 07:20 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Load a scene after 3 deaths and show the score 2 Answers

Score increases based on number of collisions at time of kill, not on single kill.,Score increases based on collisions at time of death, not based on single kill. 1 Answer

kill counter 1 Answer

My script adds +1 to variable only one time 1 Answer

Killer + assistance id for shooter game 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges