Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by Pr0n · Jul 12, 2015 at 12:44 PM · c#networkingpausesyncunity multiplayer

Change variable on all players with UNet

Hello :)

I have two players, one of them is host and second one want to change variables on all players.

alt text

How can I change var on all players from client? I need that because I'am developing simple pause network system. Anyone can help me? Thanks a lot! :)

pause.png (32.2 kB)
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
3
Best Answer

Answer by RkSanders · Jul 12, 2015 at 04:11 PM

You are meant to use the SyncVar attribute.

 [SyncVar]
 bool pause;

It will automatically keep clients updated with the value of the variable on the server. Additionally you can add a hook function if you want the client to know when the value changes:

   [SyncVar(hook = "OnPause")]
     bool pause;
 
   void OnPause(bool newValue)
 {
 print("Pause is now: " + newValue);
 }


Comment
Add comment · Show 11 · 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 Pr0n · Jul 12, 2015 at 04:27 PM 0
Share

Yeah, but it only changes var on P2 and I need change var on all players (on server and client). If you want to build pause system, you need to pause all players on network. But thanks for response. :)

avatar image RkSanders · Jul 12, 2015 at 04:44 PM 0
Share

SyncVars are sent to all clients and are buffered. You just need to check the value of the Syncvar on the hosts object.

avatar image Pr0n · Jul 12, 2015 at 05:16 PM 0
Share

But if I change var on localPlayer and call Command to change var on server, P1 has still paused on false and I need pause everything, everywhere.. What about option when I create another game object, which ad$$anonymous$$isters players. So if there is a change of variable paused, than all players are paused. And variable paused is SyncVar.

avatar image RkSanders · Jul 12, 2015 at 07:44 PM 0
Share

The client shouldn't set the pause bool. I would recommend: the client asks host to pause with a Command method, host sets pause bool and syncvar updates the host's object on all clients and OnPause() hook is called, OnPause() hook sets game to paused.

If you need special logic on every client object, yes I would create a manager class that handles the pause with one method call i.e. from the OnPause() hook.

avatar image Pr0n · Jul 12, 2015 at 08:38 PM 0
Share

Okay, so I implement Command method to Player script,which sets up bool var on Pause$$anonymous$$anager on all players, but how I can deter$$anonymous$$e that localPlayer is host?

Show more comments

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

23 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

Related Questions

[UNet] How I can send Command to non-player object? 1 Answer

How to synchronize pause and inventory scripts 2 Answers

UNET Server not setting [SyncVar] 0 Answers

Networking Sync SetActive Not Working 0 Answers

Multiple Cars not working 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