SyncList
//Creates a new instance of the list - `true` means it is owner auth.
[SerializeField] private SyncList<int> myList = new(true);
protected override void OnSpawned()
{
//Subscribing to changes made to the list
myList.onChanged += OnListChanged;
}
private void OnListChanged(SyncListChange<int> change)
{
//This is called for everyone when the list changes.
//It will log out the value, index and operation
Debug.Log($"List updated: {change}");
}
private void ChangeMyList()
{
//This will change or add a value
myList[0] = 69;
//This will remove the value
myList.Remove(69);
//This will remove the entry at the given index
myList.RemoveAt(0);
//This will clear the list
myList.Clear();
//This will insert a value at the given index
myList.Insert(1, 420f);
//This will mark the index as dirty
myList.SetDirty(0);
}
SyncListChange
Last updated