So i'm trying to make a vr multiplayer game and i get 2 errors when i start the game. 1.:NullReferenceException: Object reference not set to an instance of an object NetworkPlayer.Start () (at Assets/NetworkPlayer.cs:28) I only get it once. 2.:NullReferenceException: Object reference not set to an instance of an object NetworkPlayer.MapPosition (UnityEngine.Transform target, UnityEngine.Transform rigTransform) (at Assets/NetworkPlayer.cs:50) NetworkPlayer.Update () (at Assets/NetworkPlayer.cs:42) I get them every frame. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using Photon.Pun;
using UnityEngine.XR.Interaction.Toolkit;
public class NetworkPlayer : MonoBehaviour
{
public Transform head;
public Transform leftHand;
public Transform rightHand;
private PhotonView photonView;
private Transform headRig;
private Transform leftHandRig;
private Transform rightHandRig;
// Start is called before the first frame update
void Start()
{
photonView = GetComponent<PhotonView>();
//XRRig rig = FindObjectOfType<XRRig>();
//GetComponent<XROrigin>();
XRRig rig = GetComponent<XRRig>();
headRig = rig.transform.Find("Camera Offset/Main Camera");
leftHandRig = rig.transform.Find("Camera Offset/LeftHand Controller");
rightHandRig = rig.transform.Find("Camera Offset/RightHand Controller");
}
// Update is called once per frame
void Update()
{
if (photonView.IsMine)
{
rightHand.gameObject.SetActive(false);
leftHand.gameObject.SetActive(false);
head.gameObject.SetActive(false);
MapPosition(head, headRig);
MapPosition(leftHand, leftHandRig);
MapPosition(rightHand, rightHandRig);
}
}
void MapPosition(Transform target,Transform rigTransform)
{
target.position = rigTransform.position;
target.rotation = rigTransform.rotation;
}
}
I think it might be a problem with using and XRRig.
Please help, Happy Hollidays.