- Home /
NullReferenceException: Object reference not set to an instance of an object
I keep getting this error from my script, its not effecting the gameplay at all as far as i know, however it is getting annoying seeing it in the console every time i test
using UnityEngine;
using System.Collections;
public class SpawnPointScript : MonoBehaviour {
private Seeker seeker;
private Transform player;
public bool enablePlayerChecking;
[HideInInspector]
public bool canSpawn;
private float cooldown;
private float rateOfRefresh;
private Vector3 lastPathNode;
// Use this for initialization
void Start () {
rateOfRefresh = 0.5f;
cooldown = 0;
seeker = GetComponent<Seeker>();
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
enablePlayerChecking = true;
}
// Update is called once per frame
void Update () {
Debug.Log("Start of update");
if (cooldown > 0) {
cooldown -= Time.deltaTime;
}
if (cooldown <= 0) {
seeker.StartPath(transform.position, player.position);
***lastPathNode = seeker.lastCompletedVectorPath[seeker.lastCompletedVectorPath.Count - 1];***
float dist = Vector3.Distance(lastPathNode, player.position);
if (dist <= 3) {
Debug.Log("Path returns true");
canSpawn = true;
}else {
Debug.Log("Path returns null");
canSpawn = false;
}
cooldown = rateOfRefresh;
}
}
}
the error is specifically coming from line 44
thanks in advance
EDIT:
NullReferenceException: Object reference not set to an instance of an object SpawnPointScript.Update () (at Assets/Scripts/Evironment Scripts/SpawnPointScript.cs:44)
thats the error
unlikely that it's line 44 in the posted script - that's just a Debug.Log()
does your script find seeker
& player
? some null
checks will tell you whether you are or not...
sorry its line 39 not 44 my mistake, also it finds the player through a tag search and the seeker component is attached to the gameobject
@gjf Code is not formatted properly, line numbers are wrong. I'll edit.
@Jagster $$anonymous$$ark the line with the problem in the Code itself. Also, please post the full error from the console window.
right theres the error its outputting but im still not sure why the game is functioning perfectly as intended