Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Slences · Oct 04, 2015 at 03:42 PM · networkingvariableienumerator

Why is this method being called multiple times?

I use a script that calls a few IEnumerators in the Start method only on the server. In the following IEnumerator it simply checks for the "last man standing" in a battle:

 IEnumerator CheckCurrentBattle()
 {
     yield return new WaitForSeconds(0.1f);
 
     if (currGameState == CurrentGameState.Battle)
     {
         int alivePlayerCount = 0;
         GameObject winningPlayer = null;
         GameObject[] players = getPlayerGameObjects();
 
         foreach (GameObject player in players)
         {
             if (!player.GetComponent<PlayerStats>().isDead)
             {
                 alivePlayerCount++;
                 winningPlayer = player;
             }
         }
 
         if (alivePlayerCount == 1 || alivePlayerCount == 0)
         {
             if (alivePlayerCount == 1)
             {
                 ------>winningPlayer.GetComponent<Player>().awardPlayerWin();<------
             }
             else
                 RpcServerMessage("Draw!", false);
 
             currGameState = CurrentGameState.BattleEnding;
             StartCoroutine(EndCurrentBattle());
         }
 
     }
 
     StartCoroutine("CheckCurrentBattle");
 }

However, the server method I call where the <---arrows---> are put are getting called multiple times. For example when 3 players are connected, this method will be called 3 times. This method is just a simple server method that increases some [SyncVar] variables:

 [Server]
 public void awardPlayerWin()
 {
     playerStats.playerGold += 5;
     playerStats.playerScore += 1;
 }

Why is this method being called multiple times instead of just one time on the server?

Comment
Add comment · Show 6
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 meat5000 ♦ · Oct 04, 2015 at 04:21 PM 0
Share

Your coroutine appears to call itself.

avatar image Slences meat5000 ♦ · Oct 04, 2015 at 05:31 PM 0
Share

Yeah that's the point. It repeats itself every 0.1 second, but that's not the problem here.

avatar image meat5000 ♦ Slences · Oct 04, 2015 at 05:40 PM 0
Share

Is it being triggered by clients to run on server? So three clients trigger it three times. Does it also seem to run on clients or just the server?

Show more comments
avatar image rageingnonsense · Oct 04, 2015 at 11:16 PM 1
Share

Is this being called in the Player.Start() method? If so, you are starting it for each player you spawn.

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

34 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

Related Questions

Can't initialize NetworkVariables with NetCode for GameObjects Unity 2020.3.31f1 1 Answer

Unity networking tutorial? 6 Answers

I have a problem with variables/networking. 0 Answers

How to create a object that can only be seen by one player? 0 Answers

Send Variable. 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