Is this possible? It would help in my case.
Thanks
Is this possible? It would help in my case.
Thanks
Nope!
So, it sounds like we can’t even sync list game objects or classes? Are we going to play the guessing game on both the server and the client to see which game objects / classes are in the list right now, in a certain order, and ask both the server and the client to estimate what happens next?
You can sync GameObjects with SyncVar, I think, so maybe I’m wrong in this. Why don’t you give it a try?
I did try, and I reported it when it crashed the Unity editor while compiling the script.
What would be a suggested work around for syncing a list of Objects? (Will need probably only with basic data types)
Thanks @seanr . This seems similar to what I’m doing. Basically, using a SyncListStruct. What’s somewhat frustrating is that you can’t change individual values in the struct (for example: player.score+=2) , you need to create a whole new struct and copy all the values over. With objects you can change it which makes it much quicker to code and is less error prone. Am I understanding this correctly or perhaps missing something? Any suggestions to avoid this situation?
I think you can just set the values like
public struct Foo {
int score;
}
//....
Foo player;
//...
SyncListPlayerList.Add(player);
//...
//Your "player" example struct object is SyncListPlayerList[i], where i is a given integer index value.
Foo newPlayer = SyncListPlayerList[i];
newPlayer.score += 2;
SyncListPlayerList[i] = newPlayer;
Ah I see. That is faster than what I’m doing now. Thanks!
That’s actually the official C# way of updating data in array elements, due to how generic Lists work under the hood. You get the reference, set new data to the reference’s members, then set the reference back into the original reference.