- Home /
Parameter becomes null through UNet Rpc
Below is a fragment of my code where the Rpc is called. You can see that I am doing some extra checks to make sure that the parameter being passed is not null by making a new copy of the dictionary I want to pass and then adding a value and to top it off a quick log so I can see in the editor there's no funny business.
 Dictionary<int, float> parameter = new Dictionary<int, float>(resources);
 
 if(parameter != null)
     Debug.Log("resources != null");
 else
     Debug.Log("resources == null");
 
 parameter.Add(1, 4.3f);
 
 if(networkController.isServer)
 {
     networkController.RpcSendRList(parameter);
 }
When running this as the server or the client, parameter is logged as not being null before I even add the KeyValuePair<int, float> of (1, 4.3f), so I'm sure parameter is not null.
Below are the Rpcs being called:
 [ClientRpc]
 public void RpcSendRList(Dictionary<int, float> _rList)
 {
     if(_rList != null)
         opponentResources = _rList;
     else
         Debug.Log("null dict");
 }
The result in the editor is that it logs "null dict". I have debugged this function by putting a breakpoint in just so I can be sure when reading the _rList parameter that it is null and indeed the result is null.
If I have logged the value before as to not be null then why is it being received as null by the client?
Answer by n1gth · Jul 15, 2015 at 11:18 AM
You can only send certain simple types through remote calls (Commands, ClientRpcs). These include int, long, float, Vector3, Color... but do not include complex types like Dictionaries.
I think I remember this from the legacy system and I guess I hoped it had changed in the back of my head. This really should be stated on the documentation! http://docs.unity3d.com/$$anonymous$$anual/UNetActions.html
But there is this. I have not tried implementing it though.
http://docs.unity3d.com/ScriptReference/Networking.SyncList_1.html
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Change variable on all players with UNet 1 Answer
Rpc is received by client but Cmd is not received by server 2 Answers
Distribute terrain in zones 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                