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 /
  • Help Room /
avatar image
0
Question by Seathan · Jul 01, 2020 at 01:08 AM · networkingupdatebooleanifcommand

Server Command Call not working when inside an if which checks for hasAuthority and a bool

Hi, let me start by saying that I'm trying to find a way to make this only happen once when a player connects in a function like OnClientConnect or something (and haven't found it yet - any help is welcome), but the actual problem here is this weird behaviour; I'm not sure if it's something I'm doing wrong or if it's a bug... Here's the thing; inside the Update() I call a server command to update the player name and player skill on all the clients joining the server. I wanted it tell the server only once so to call this only once I added a boolean which would make that loop run continuously until it gets updated on the clients. So... Without the added bool condition, it works, the player name and skill is updated, but the server is "spammed" continuously by the Update() method to tell it to update the name on all the other clients even after the update has been done. With the added bool condition, it gets inside the loop (I do get the Debug.Log message in the console) but the player name and skill are never updated ... What gives ? Thanks in advance.

Working code:

  public override void OnStartAuthority()
  {
     CmdSet_pe_Player(PlayerPrefs.GetString("player_name"), PlayerPrefs.GetString("win_ratio"));
  }
  private void Update()
  {
      if (hasAuthority)
          CmdSet_pe_Player(PlayerPrefs.GetString("player_name"), PlayerPrefs.GetString("win_ratio"));
  }
  [Command]
  void CmdSet_pe_Player(string n, string s)
  {
     playerName.text = n;
     playerSkill.text = s;
     RpcSet_pe_Player(n, s);
  }
  [ClientRpc]
  void RpcSet_pe_Player(string n, string s)
  {
     playerName.text = n;
     playerSkill.text = s;
  }


Not working code :

  bool clientUpdated = false;
  public override void OnStartAuthority()
  {
     CmdSet_pe_Player(PlayerPrefs.GetString("player_name"), PlayerPrefs.GetString("win_ratio"));
  }
  private void Update()
  {
     if (hasAuthority && !clientUpdated)
     {
         Debug.Log("ClientUpdated");
         CmdSet_pe_Player(PlayerPrefs.GetString("player_name"), PlayerPrefs.GetString("win_ratio"));
         clientUpdated = true;
     }
  }
  [Command]
  void CmdSet_pe_Player(string n, string s)
  {
     playerName.text = n;
     playerSkill.text = s;
     RpcSet_pe_Player(n, s);
  }
  [ClientRpc]
  void RpcSet_pe_Player(string n, string s)
  {
     playerName.text = n;
     playerSkill.text = s;
  }
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

0 Replies

· Add your reply
  • Sort: 

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

256 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image

Related Questions

Calling Bool in Network Command Not Working 0 Answers

Network is spawning more objects then desired 1 Answer

Instantiating over the Network, good way? 1 Answer

CommandAttribute doesn't work properly 1 Answer

i just can't seem to figure out how to make a voting system, using SyncVar hooks and commands 0 Answers


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