- Home /
Question by
SaphalAryal · Apr 03, 2021 at 03:44 AM ·
networkingnullreferenceexceptionpunhashtable
(Pun2) Hastable. Null Reference Error
I have tried to sync the current gun hold by player Set Custom Properties .It work well but not I want to sync the player current skin using same idea of as used in gun. But it doesn't work .it shows me null reference expctection.
the code is:
private void ActivateRedSkill(int CurrentRedIndex)
{
Rend.material= new Material(RedSkillCollection[CurrentRedIndex]);
if (PV.IsMine)
{
Hashtable RedHash = new Hashtable();
RedHash.Add("CurrentRedIndex",CurrentRedIndex);
PhotonNetwork.LocalPlayer.SetCustomProperties(RedHash);
}
}
private void ActivateBlueSkill(int CurrentBlueIndex)
{
Rend.material= new Material(BlueSkillCollection[CurrentBlueIndex]);
if (PV.IsMine)
{
Hashtable BlueHash = new Hashtable();
BlueHash.Add("CurrentBlueIndex",CurrentBlueIndex);
PhotonNetwork.LocalPlayer.SetCustomProperties(BlueHash);
}
}
private void EquipGun(int index)
{
if (index == preitemIndex)
return;
itemIndex=index;
Guns[itemIndex].gameObject.SetActive(true);
if(preitemIndex != -1)
{
Guns[preitemIndex].gameObject.SetActive(false);
}
preitemIndex=itemIndex;
if (PV.IsMine)
{
Hashtable hash = new Hashtable();
hash.Add("itemIndex", itemIndex);
PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
}
}
public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
{
if (!PV.IsMine && targetPlayer==PV.Owner)
{
if(PhotonNetwork.LocalPlayer.CustomProperties.ContainsKey("itemIndex"))
EquipGun((int)changedProps["itemIndex"]);
if(PhotonNetwork.LocalPlayer.CustomProperties.ContainsKey("CurrentRedIndex"))
ActivateRedSkill((int)changedProps["CurrentRedIndex"]);
if(PhotonNetwork.LocalPlayer.CustomProperties.ContainsKey("CurrentBlueIndex"))
ActivateBlueSkill((int)changedProps["CurrentBlueIndex"]);
}
Here the all the function work well in local player .Also Equip gun function and it's custtom properties works well and the current gun hold by player is sync all over the player .But the ActiveRedSkill And Active BlueSkill WOrks only in local player But it is not Sync to other player due to null reference expectation in (ONPLAYERPROPERTIES UPDATE)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613031701im_/https://answers.unity.com/themes/thub/images/avi.jpg)