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 Darrek13 · Apr 02, 2017 at 10:03 AM · unity 5networkingsynchronizationsync

UNET SyncVar on a NetworkInstanceId SyncList structure not updating across network

Hi,

I've been looking for a solution on the web for the past hours, time to ask it myself... I have a SyncList structure with NetworkInstanceIds in it to share across all clients but it doesn't get updated. The list is up to date on the server for each player when I modify it, but it doesn't spread. I'm doing all the changes on the server and I don't know what to do to solve this.

Here's when I define the SyncVar :

     [SyncVar]
     public Structures.SyncListNetworkInstanceId secrets = new Structures.SyncListNetworkInstanceId();

Then I modify it here on the server only (I guess you don't need the full details of the project but I just need to pass the id of the secret objects) :

     [Server]
     public void DispatchSecrets()
     {
         // TODO : Something more proper and modulable to the number of players (have a problem with syncvar first to resolve)
 
         int i = 0;
         secrets[0].GetComponent<Secret>().shared = true;
         secrets[1].GetComponent<Secret>().shared = true;
         secrets[6].GetComponent<Secret>().shared = true;
         List<GameObject> tmpSecrets = secrets;
         tmpSecrets.Insert(5, secrets[0]);
         tmpSecrets.Insert(11, secrets[1]);
         tmpSecrets.Insert(10, secrets[6]);
         foreach (Player p in team1.GetComponent<Team>().players)
         {
             Debug.Log(p.deviceName);
             Debug.Log(tmpSecrets[i].GetComponent<Secret>().netId);
             p.secrets.Add(tmpSecrets[i].GetComponent<Secret>().netId);
             p.secrets.Add(tmpSecrets[i + 1].GetComponent<Secret>().netId);
             p.secrets.Add(tmpSecrets[i + 2].GetComponent<Secret>().netId);
             p.secrets.Add(tmpSecrets[i + 3].GetComponent<Secret>().netId);
             p.secrets.Add(tmpSecrets[i + 4].GetComponent<Secret>().netId);
             p.secrets.Shuffle();
             p.RpcUpdateProfile();
             i++;
         }
 
         i = 15;
         secrets[15].GetComponent<Secret>().shared = true;
         secrets[16].GetComponent<Secret>().shared = true;
         secrets[21].GetComponent<Secret>().shared = true;
         tmpSecrets.Insert(20, secrets[0]);
         tmpSecrets.Insert(26, secrets[1]);
         tmpSecrets.Insert(25, secrets[6]);
         foreach (Player p in team2.GetComponent<Team>().players)
         {
             Debug.Log(p.deviceName);
             Debug.Log(tmpSecrets[i].GetComponent<Secret>().netId);
             p.secrets.Add(tmpSecrets[i].GetComponent<Secret>().netId);
             p.secrets.Add(tmpSecrets[i + 1].GetComponent<Secret>().netId);
             p.secrets.Add(tmpSecrets[i + 2].GetComponent<Secret>().netId);
             p.secrets.Add(tmpSecrets[i + 3].GetComponent<Secret>().netId);
             p.secrets.Add(tmpSecrets[i + 4].GetComponent<Secret>().netId);
             p.secrets.Shuffle();
             p.RpcUpdateProfile();
             i++;
         }
     }


Can anyone help me ? That'd be great ! Thanks !

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

Answer by Darrek13 · Apr 06, 2017 at 10:04 PM

OK so I figured out what was the problem !

The definition of my structure was wrong to be used with UNET, that's why it wasn't synchronizing over the network. Below is the correct code, hoping it'd help anyone :

 public static class Structures : object {
 
     public class SyncListNetworkInstanceId : SyncListStruct<NetID> { }
 
     public struct NetID
     {
         public NetworkInstanceId netID;
     }
 }

I changed a bit the core of the function below, but you just need to look at how I add new items to my structure.

     [Server]
     public void DispatchSecrets()
     {
         List<GameObject> tmpListSecrets = secrets.Take(secrets.Count / NUMBER_TEAMS).ToList();
         foreach (GameObject team in teams)
         {
             Team t = team.GetComponent<Team>();
             int numberOfSharedSecrets = t.players.Count == 1 ? 1 : t.players.Count - 1; // DEBUG : 1 to test with one player only (host test)...
             for (int i = 0; i < t.players.Count; i++)
             {
                 Player p = t.players[i];
                 for (int j = 0; j < numberOfSharedSecrets; j++)
                 {
                     Player nextPlayer = t.players[(i + 1) % t.players.Count];
                     Secret secret = tmpListSecrets[0].GetComponent<Secret>();
                     secrets.Find(s => s.GetComponent<Secret>().Equals(secret)).GetComponent<Secret>().shared = true;
                     p.secrets.Add(new Structures.NetID() { netID = secret.netId });
                     if (!nextPlayer.playerName.Equals(p.playerName))
                     {
                         nextPlayer.secrets.Add(new Structures.NetID() { netID = secret.netId });
                     }
                     tmpListSecrets.Remove(secret.gameObject);
                 }
                 int tmp = 5 - p.secrets.Count;
                 for (int j = 0; j < tmp; j++)
                 {
                     Secret secret = tmpListSecrets[0].GetComponent<Secret>();
                     p.secrets.Add(new Structures.NetID() { netID = secret.netId });
                     tmpListSecrets.Remove(secret.gameObject);
                 }
                 p.secrets.Shuffle();
                 p.RpcUpdateProfile();
             }
         }
     }


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

Networking Sync SetActive Not Working 0 Answers

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

Networking lobby player image not working on host and other clients 0 Answers

How fast do Syncvars synchronize? 1 Answer

Unity hlapi networktransform rigidbody rotation and interpolation issue 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