I am trying out Network for Gameobjects with Distributed Authority. I cannot get the Network Variables to behave as I expect them to.
Server (host) spawns a player object, owner himself
Server sets a network variable on the new object. It works
Server spawns a player object, SpawnAsPlayerObject with a client as owner
Server tries to set the network variable on that object, but get error
Write permissions (Owner) for this client instance is not allowed!
It does not matter if I have write permissions on the network variable as Server or Owner, the Server can never set the variable. Which is annoying, I would like the server to assign teams for example.
This is as intended going by the documentation, at least where the write permission is Owner and the object is owned by the client. I queried this once and was told it’s to avoid concurrency issues where both client and server could write to the variable at the same time.
Well, what is the point of having the Server write permission then? Is not expected that the Server should be a able to set network variables with Server write permission, after they are spawned. Even though they are owned by the client?
Ok I got it working now finally. The correct pattern is to set all network variables on the server BEFORE spawning. Then read those in the OnNetworkSpawn method and properly initialize the object. Still weird that the server cannot set network variables for clients owning the object but with this solution I do not need it anymore.