#Server can't sync value of SyncVar to clients

6 messages · Page 1 of 1 (latest)

hidden orbit
#

I have a Syncvar which I want to change in a ServerRpc function, but it throws and error. The value of the variable changes on the server.

NullReferenceException: Object reference not set to an instance of an object
NetworkedSack.sync___set_value_owner (Player value, System.Boolean asServer) (at <028e38bd11fc4180a38f5b3c6b1bd291>:0)
NetworkedSack.setOwner (Player owner) (at Assets/Scripts/NetworkedSack.cs:59)

What I can understand from this is that FishNet makes a function called sync___set_value_owner which would synchronize the value of the variable to clients. How could I find out what is the Object reference that has a null value, or start debugging this?

thin valley
#

Or maybe you're trying to call the ServerRpc on an object that is not networked/initialized yet

hidden orbit
#

I think the Player object in the parameter can't be null because it sets the player as the value of the owner variable on the server, the error is only thrown when the server tries to sync that value to the clients. The object has a networkObject component and the class in my script derives from NetworkBehaviour so it should be networked. What does initialized mean exactly? How can I check if an object is initialized on the network?

thin valley
#

It need to be Spawned (both the object referenced and the object you call the RPC on) first, too

hidden orbit
#

I couldn't fully understand the problem, but I could solve it by making an empty object adding all the components of the prefab and copying the child components. So the problem was that my object was an instance of a prefab. I will try to investigate this when I have the time. Thanks for your help @thin valley