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 Tanoshimi2000 · Jan 11, 2016 at 01:42 AM · networkingserverclientsync

How do I use uNET to send client data to server (SyncListBool goes the wrong way)?

OK, so I've looked for an answer to this, but they're all using the old networking system. I know that SyncListBool gives me my array of bools, and when I use them in the server, the client gets updated. What I need is the opposite. I need the client to own, keep track of, and send those values to the server.

I have a client that has 8 switches. The the client changes those 8 switches values on clicks. The server needs to know values of those switches. I suppose I could continue using the SyncListBool on the server, and have the client call a function that the server listens to in order to change the servers values. But I'd rather just have data from the server sent to the client, and data from the client (including the values in the SynList) sent to the Server.

 public SyncListBool ButtonState = new SyncListBool();

That gives the client the value of those Buttons, but I want to set those values from the client. Any ideas?

Comment
Add comment · Show 1
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 Tanoshimi2000 · Jan 11, 2016 at 01:59 PM 0
Share

In case this is too much, in short. I want ONE list of Booleans that is set by the Client, and shown in the server.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by seanr · Jan 11, 2016 at 03:46 PM

use a command and pass the index of the switch

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 Tanoshimi2000 · Jan 12, 2016 at 06:20 PM 0
Share

Yeah, I was thinking this is the way to go, but I hadn't gotten it working. And I definitely don't want to look through my controls and send them all during the FixedUpdate event. I guess I can just write a command function, and only send it when that switch is clicked on, or the actual value changes, right?

avatar image Tanoshimi2000 · Jan 13, 2016 at 01:25 AM 0
Share

@seanr For some reason, that doesn't seem to be working. What I want is to have a set of toggle switches, owned by the server, but set by the client. Both the client and server are displaying them in the GUI event, and changing them when clicked on. With my code below, changes set on the server are seen on the client, but changes made on the client do not get reflected on the server.

     public SyncListBool ButtonState = new SyncListBool();// 9 virtual buttons... for now
     public Texture btnOnTexture;
     public Texture btnOffTexture;
 
     void OnGUI()
     {
         // On server show local player (server).  On client show NOT local Player (server)
             for (int i = 0; i < ButtonState.Count; i++)
             {
                 GUI.TextArea(new Rect(350, 100 + (i * 25), 150, 20), "Button " + i.ToString() + ": " + ButtonState[i].ToString());
                 if (ButtonState[i])
                 {
                     if (GUI.Button(new Rect(10 + ((i % 2) * 180), 10 + ((i % 5) * 80), 150, 60), btnOnTexture))
                     {
                         
                         ButtonState[i] = !ButtonState[i];
                         Debug.Log("(Locally) Turned off button " + i.ToString());
                         CmdSetButton(i, false);
                     }
                 }
                 else
                 {
                     if (GUI.Button(new Rect(10 + ((i % 2) * 180), 10 + ((i % 5) * 80), 150, 60), btnOffTexture))
                     {
 
                         ButtonState[i] = !ButtonState[i];
                         Debug.Log("(Locally) Turned on button " + i.ToString());
                         CmdSetButton(i, true);
 
                     }
                 }
             }
     }
 
     [Command]
     void CmdSetButton(int index, bool value)
     {
         Debug.Log("(Remotely) Setting " + index + " to " + value);
         ButtonState[index] = value;        
     }

This is almost straight from the code example for [Command], yet that debug statement never gets tripped. Changes made on the server show on the Client. Changing values on the client show on the client, but do not show on the Server (where I need them).

What's wrong with my code?

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

43 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

Related Questions

Unity networking tutorial? 6 Answers

Multiplayer syncronisation 1 Answer

Local Server and Client 1 Answer

Do i need to have 2 seperate apps communicating for server/client relationship? 2 Answers

Network how to send data/activate function 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