: Object reference not set to an instance of an object on custom properties
hello im making a multiplayer game to play with my friends and im trying to make a button to set a ready state to player but i get this error
NullReferenceException: Object reference not set to an instance of an object
SetReady.Ready () (at Assets/Scripts/SetReady.cs:24)
Shoottest+<>c__DisplayClass6_0.<Update>b__0 (UnityEngine.InputSystem.InputAction+CallbackContext _) (at Assets/Scripts/Shoottest.cs:29)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Utilities/DelegateHelpers.cs:46)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
this is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Hastable = ExitGames.Client.Photon.Hashtable;
public class SetReady : MonoBehaviourPunCallbacks
{
public bool ReadyP;
public Hastable hash;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void Ready()
{
bool Ready = (bool)PhotonNetwork.LocalPlayer.CustomProperties["Ready"];
ReadyP = Ready;
Ready = true;
Hastable _hash = new Hastable();
hash = _hash;
_hash.Add("Ready", Ready);
PhotonNetwork.LocalPlayer.SetCustomProperties(_hash);
}
}
why it does this?
Answers
-
Initialize this: public Hastable hash;
Like this:
public Hashtable hash = new Hashtable();
0