- Home /
SyncList TO
I asked question about using SyncList< TO > before, but unfortunately no one answered.
But Hey , Dont Worry. I read almost all networking documentation and off course this but i dont got the hint to declare SyncList< TO > .
So i read the **(UnityEngine.Networking)** script and then i got the hint :P .
Here we go :) Hope this helps you out .
Answer by Zoelovezle · Jan 05, 2016 at 07:53 PM
using UnityEngine;
using System.Collections;
using UnityEngine.Networking ;
public class MySyncVars : NetworkBehaviour {
// I am declaring Vector3 Sync LIst , for that small hint
public class SyncListVector : SyncList<Vector3> {
protected override void SerializeItem(NetworkWriter writer, Vector3 item)
{
writer.Write(item);
}
protected override Vector3 DeserializeItem(NetworkReader reader)
{
return reader.ReadVector3();
}
}
public SyncListVectors myVector3 = new SyncListVectors() ;
}
//After this class now we can just create a SyncList of type Vector3 as ,
public SyncListVector3 mySyncVectorList = new SyncListVector3() ;
//And its done now ,
public Vector3 someVector ;
void Start()
{
mySyncVectorList.Add(someVector) ;
//Now this will sync and work same as other SyncList
}
Documentations for Reference :
Great solution. But list with vectors will not be syncronized for new client. New client has empty list at start. Default lists like SyncListString, SyncListFloat , SyncListInt etc. works fine.
Answer by svendkiloo · Jan 12, 2017 at 09:03 AM
Thank you @Zoelovezle. I've used the solution from your answer above to keep a list of Vector3
objects synced, and it works fine. However, I get these warnings whenever the project compiles:
UNetWeaver warning: The class / struct SyncListVector3 has no public or non-static fields to serialize
Since it works, I presume the warning is wrong?
If I add a public field, say:
public bool boolThatMakesNoDifference1;
the warnings go away, but I'd rather not do that. Is this a "bug" in UNetWeaver that it warns, or am I doing something "cheeky"? :)
Answer by Alturis2 · Aug 01, 2017 at 01:26 AM
No, it looks to me like you are not using your SyncListVector class at all but instead the built in SyncListVector3
Your answer
![](https://koobas.hobune.stream/wayback/20220612055054im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why Does Adding to My SyncListStruct Break SyncVar? 0 Answers
Networking: how to sync complex objects 0 Answers
A node in a childnode? 1 Answer
How to Sync List 1 Answer
SyncVar on objects in a list 1 Answer