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 firestorm713q · Oct 12, 2015 at 07:45 AM · unity 5multiplayersynchronizationsyncmatchmaking

[UNET] Unable to run [Command]s on remote client

Update: Commands definitely are working on the host. Remote Clients, on the other hand simply aren't calling them.

Update: I seem to have been wrong. Whether or not they're set via a command, the Host never sees the synclist and most of the syncvars from the client. I can get the remote client to list both the host's cards and their own cards, but the host cannot see anything from the client. Notably, the User Unique Identity is synchronized across the host and client.

Original Post: I'm making a two player card game, and multiplayer is being implemented via the matchmaker. The PlayerPrefab has a NetworkID component, and it is set to have authority. I'm using a single UserHandler class to handle every bit of data for the user (deck info, unique identity, etc.). Basically, when a player connects, they're supposed to provide their deck lists (position, lineup and sideboard) and deck name to the server. If I remove the [Command] attribute on the functions that set all the SyncVars and SyncListInts, then the client has all data for both the client and the host players, but the host only has its own data. When I switch them back to [Command]s, the host has all data for both, but the client only has the Host's data (which is backwards from what I'd expect.

I've been fighting with Rpc/Command stuff for about a week now, and I'm just getting nowhere. I have no idea what I've done wrong, because if it's out of sync on one, it would make sense if it were completely out of sync on the other. Relevant Code Below:

 public class UserHandler : NetworkBehaviour 
 {
 [SyncVar]
 public string UserUniqueIdentity;

 NetworkInstanceId UserNetID;
 
 Transform myTransform;

 [SyncVar]
 public string DeckName;

 public SyncListInt UserDeckPositions = new SyncListInt();
 public SyncListInt UserDeckLineup = new SyncListInt();
 public SyncListInt UserDeckDugout = new SyncListInt();

 public List<int> ClientUserDeckPositions = new List<int>();
 public List<int> ClientUserDeckLineup = new List<int>();
 public List<int> ClientUserDeckDugout = new List<int>();

 public override void OnStartLocalPlayer () {
     Debug.Log("Beginning Setup");
     GetUserDeck();
     CmdProvideUserDeckToServer();
     NetworkLobbyUIHandler.LobbyUISingleton.ListUserCards (GameDataHandler.GameDataSingleton.User.CurrentDeck);
     GetNetIdentity();
     SetIdentity();
     //Debug.Log("Done setting up");
     CmdDoneSettingUp();
 }

 [Client]
 void GetUserDeck()
 {
     Deck deck = GameDataHandler.GameDataSingleton.User.CurrentDeck;

     for (int i = 0; i < deck.Positions.Length; i++)
     {
         ClientUserDeckPositions.Add(deck.positions[i]);
     }
     for (int i = 0; i < deck.StartingLineup.Count; i++)
     {
         ClientUserDeckLineup.Add(deck.StartingLineup[i]);
     }
     for (int i = 0; i < deck.Sideboard.Count; i++)
     {
         ClientUserDeckSideboard.Add(deck.Sideboard[i]);
     }
     CmdProvideDeckNameToServer(deck.DeckName);
     Debug.Log(DeckName);
 }

 [Command]
 void CmdProvideDeckNameToServer(string deckName)
 {
     Debug.Log(deckName);
     DeckName = DeckName;
 }

 [Command]
 void CmdProvideUserDeckToServer()
 {
     //UserData user = GameDataHandler.GameDataSingleton.User;
         Debug.Log ("Number of UserDeckPositions on the Client:"+ClientUserDeckPositions.Count);
     for (int i = 0; i < ClientUserDeckPositions.Count; i++)
     {
         UserDeckPositions.Add(ClientUserDeckPositions[i]);
     }
     for (int i = 0; i < ClientUserDeckLineup.Count; i++)
     {
         UserDeckLineup.Add(ClientUserDeckLineup[i]);
     }
     for (int i = 0; i < ClientUserDeckSideboard.Count; i++)
     {
         UserDeckSideboard.Add(ClientUserDeckSideboard[i]);
     }
     //RpcListDeckLineup();
 }


 [Client]
 void GetNetIdentity()
 {
     //Debug.Log("Did I Crash before or after I got my NetIdentity?");
     UserNetID = GetComponent<NetworkIdentity>().netId;
     CmdProvideNetIDToServer(MakeUniqueIdentity());
 }
     string MakeUniqueIdentity()
 {
     string UserName = "Player " + UserNetID.ToString() + " " + DeckName;
     Debug.Log ("Making Unique Identity: " + UserName);
     CmdProvideNetIDToServer(UserName);
     return UserName;
 }

 void SetIdentity()
 {
     Debug.Log("Setting Net Identity...");
     if(!isLocalPlayer)
     {
         Debug.Log("Client set identity Reached");
         transform.name = UserUniqueIdentity;
     }
     else
     {
         transform.name = MakeUniqueIdentity();
     }
 }
 }
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
0
Best Answer

Answer by firestorm713q · Oct 14, 2015 at 01:13 AM

This is simply the wrong way to approach this problem. As far as I can tell, the HLAPI doesn't support this kind of peer-to-peer method of doing things, and so the best way to handle player-data is to find a way to load it in a server-authoritative way. If you need something more like this, then you'll likely have to delve into the LLAPI, which is not something I feel like doing. Shortest version, Commands can't be run on remote clients, only the local client and the server.

My overall solution is to load up everything on the NetworkHandler using WWW and php.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Synchronizing multiplayer car game 1 Answer

UNET SyncVar on a NetworkInstanceId SyncList structure not updating across network 1 Answer

Unet assigning local player Authority to a gameObject. 1 Answer

Help| Sync' boolean variable (Friendly Fire) 0 Answers

What does the Unity act as when you have a Client-Server system? What are you paying for? 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