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 /
This question was closed Mar 05, 2018 at 05:01 AM by Vencarii for the following reason:

Other

avatar image
0
Question by Vencarii · Mar 04, 2018 at 10:47 PM · networkingvariablelong

SyncVar of type long isn't updated on clients

Hello, I have a SyncVar called "money" of type long in my Player gameobject with a hook to the OnMoneyChange() method. This method updates a Text Gameobject to show the amount of money to the player. It works fine on the Host, but it doesn't on the Client.

I used Debug.Log("money="+money); to show the amount of money on the Client when the player moves. It shows 30000 as expected. But when I buy something in my game, the amount is still at 30000, so it doesn't sync with the server. And I don't see any of the debug messages in the OnMoneyChange() method.

Code on my player gameobject:

 public class Player : NetworkBehaviour
 {
     [SyncVar(hook = "OnMoneyChange")]
     public long money = 0;
     
     void Start()
     {
         // init stuff for the local player
         if (isLocalPlayer) {
             gameObject.tag = "LocalPlayer";
             targetPosition = transform.position;
             money = 30000;
         }
     }
     
     // hook that updates the money text
     public void OnMoneyChange(long newMoney)
     {
         Debug.Log("OnMoneyChange called");
         if (!isLocalPlayer) {
             return;
         }
 
         money = newMoney;
         Debug.Log(GameObject.FindGameObjectWithTag("MoneyText"));
         GameObject.FindGameObjectWithTag("MoneyText").GetComponent<Text>().text = money.ToString("###,###,###") + " $";
         Debug.Log("OnMoneyChange done");
     }
     
     // much more....
 }
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

  • Sort: 

Follow this Question

Answers Answers and Comments

116 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

Related Questions

How to sync a varible managed by the clients using UNET? 0 Answers

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

Unity networking tutorial? 6 Answers

Send Variable. 1 Answer

How to create a object that can only be seen by one player? 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