Hi guys i have this werid bug where a int parameter passed to an RPC suddenly becomes null. The error message looks like this:
Sending RPC failed because 'UpdateCallbackVariablesUnit' parameter 7 was null
UnityEngine.NetworkView:RPC(String, NetworkPlayer, Object[])
MouseFeedbackControl:UpdateTopSelectedUnit(NetworkPlayer, Int32) (at Assets/Scripts/MouseFeedbackControl.cs:307)
The RPC is called by this line in OnGUI() in the client:
networkView.RPC ("UpdateTopSelectedUnit", RPCMode.Server, Network.player, 0);
And here is the code containing the error. The function is supposed to sync the client to the server (authoritative server):
[RPC] public void UpdateTopSelectedUnit(NetworkPlayer player, int index)
{
int spellcasttype = 0;
int spellID = 0;
int buildID = 0;
string spellname = null;
string buildname = null;
// PLAYER 1
if(player.ToString() == "1")
{
if(selectedUnits1.Count > 0)
{
topSelectedUnit1 = selectedUnits1[0] as GameObject;
if(topSelectedUnit1.GetComponent<Unit>().UnitSpells.Count > 0)
{
spellID = (int)topSelectedUnit1.GetComponent<Unit>().UnitSpells[index];
spellname = topSelectedUnit1.GetComponent<Unit>().UnitSpellNames[index] as string;
spellcasttype = (int)topSelectedUnit1.GetComponent<Unit>().UnitSpellCastType[index];
}
if(topSelectedUnit1.GetComponent<Unit>().UnitKnowArray.Count > 0)
{
buildID = (int)topSelectedUnit1.GetComponent<Unit>().UnitKnowArray[index];
buildname = topSelectedUnit1.GetComponent<Unit>().UnitKnowNamesArray[index] as string;
}
//error is in the following line
networkView.RPC("UpdateCallbackVariablesUnit", player, player,
topSelectedUnit1 != null,
!topSelectedUnit1.GetComponent<Unit>().isStationary,
topSelectedUnit1.GetComponent<Unit>().unitHasAttack,
topSelectedUnit1.GetComponent<Unit>().isBarracks,
spellcasttype,
spellID,
spellname,
buildID,
buildname,
topSelectedUnit1.GetComponent<Unit>().UnitSpells.Count,
topSelectedUnit1.GetComponent<Unit>().UnitKnowArray.Count);
}
else
topSelectedUnit1 = null;
}
}
I can’t see where the mistake is, please help.