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 JMetcalfe201 · Dec 05, 2015 at 06:17 PM · networkingunity5synchronizationinitialization

SyncList not initialized on server when created as localPlayerAuthority on client

I'm having a lot of trouble with SyncLists. I have a script on my player prefab that is being spawned by the default NetworkManager with localPlayerAuthority that needs to have a list of ints that are synced between clients.

Currently when I start a host and then connect as a client, the two player's SyncList's will be properly initialized on the client but on the server only the host's SyncList is initialized.

When I run the below code the console on the server reads:

NetID 3's sync list on editor contains 5 things
NetID 4's sync list on editor contains 0 things


While on the client it reads:

NetID 3's sync list on standalone contains 5 things
SyncList not initialized
SyncList not initialized
SyncList not initialized
SyncList not initialized
SyncList not initialized
NetID 4's sync list on standalone contains 5 things

Here is my code:

 public class PlayingField : NetworkBehaviour
 {
     public SyncListInt monsterSyncList = new SyncListInt();
     public GameObject tempMonsterCard;
 
     void Awake()
     {
         monsterSyncList.Callback = OnMonsterChanged;
     }
 
     void Start()
     {
         if (hasAuthority)
         {
             Debug.Log("Is local player");
 
             for (int i = 0; i < 5; i++)
             {
                 monsterSyncList.Add(-1);
             }
         }
 
         Debug.LogError("NetID " + netId + "'s sync list on " + (Application.isEditor ? "editor " : "standalone ") + "contains " + monsterSyncList.Count + " things");
     }
 
     public bool setMonsterCardByIndex(GameObject card, int i)
     {
         if (hasAuthority)
         {
             monsterSyncList[i] = card.GetComponent<ICard>().cardID;
             return true;
         }
 
         return false;
     }
 
     private void OnMonsterChanged(SyncListInt.Operation op, int index)
     {
         if (SyncListInt.Operation.OP_SET == op && !hasAuthority)
         {
             if (monsterSyncList[index] != -1)
             {
                 Debug.Log("Synced");
             }
         }
     }
 }

Any help would be appreciated. I've been working at this for hours with no end in sight.

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 Morgenstern_1 · Jun 23, 2016 at 08:51 AM

This is a really old topic I see, but what you're trying to do is sync data from a client to a server, which is not the purpose of sync lists regardless of who has authority.

You should ALWAYS add/remove from a SyncList on the server, and that data will get populated down to all the clients. SyncLists will not send data in the other direction.

It's generally bad practice to have anything other than the server changing data like that anyway - it opens up your game to cheating!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Inheritance and uninitialized synclists 2 Answers

ScriptableObjects and SyncVars, is it posible? 1 Answer

[UNet] Best practice to cache components in NetworkBehaviour 0 Answers

Unet CCU Exceeded by appID: Not going down 0 Answers

Changing rooms and spawning players with Multiplayer Example 2 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