- Home /
"NullReferenceException: Object reference not set to an instance of an object"
I was using this code to connect my players to the object, but i get this error:
NullReferenceException: Object reference not set to an instance of an object
NetworkCharacter.Update () (at Assets/Scripts/NetworkCharacter.cs:10)
Heres the code:
using UnityEngine;
public class NetworkCharacter : Photon.MonoBehaviour
{
private Vector3 correctPlayerPos = Vector3.zero; // We lerp towards this
private Quaternion correctPlayerRot = Quaternion.identity; // We lerp towards this
// Update is called once per frame
void Update()
{
if (!photonView.isMine)
{
transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
// We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
myThirdPersonController myC = GetComponent<myThirdPersonController>();
stream.SendNext((int)myC._characterState);
}
else
{
// Network player, receive data
this.correctPlayerPos = (Vector3)stream.ReceiveNext();
this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
myThirdPersonController myC = GetComponent<myThirdPersonController>();
myC._characterState = (CharacterState)stream.ReceiveNext();
}
}
}
Ive been trying to figure it out, but i cant find the answer. Thanks!
what is photonView - it's not defined here, is it implicitly defined from Photon.$$anonymous$$ono or do you need something like
public PhotonView photonView
Answer by theLittleSettler · Jan 28, 2014 at 09:25 AM
The variable photonView isn't storing anything.
I'm assuming it is defined somewhere, or else you would probably get a different error.
Use Right click-> Find all References to find where it's supposed to be initialized. Go from there.
Hope that helps.
Thanks so much, i forgot to add a script to the character.
Your answer
Follow this Question
Related Questions
photon player freak out! 1 Answer
Text name above player's head in Photon 3 Answers
scoreboard for multiplayer game 0 Answers
Two Photon problems 0 Answers
Help with Photon Network Functions C# 2 Answers