Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jagster · Dec 22, 2014 at 04:30 PM · errorobjectnullreferenceexceptionreferenceconsole

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

Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gjf · Dec 22, 2014 at 03:24 PM 0
Share

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...

avatar image Jagster · Dec 22, 2014 at 03:36 PM 0
Share

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

avatar image meat5000 ♦ · Dec 22, 2014 at 03:43 PM 0
Share

@gjf Code is not formatted properly, line numbers are wrong. I'll edit.

avatar image meat5000 ♦ · Dec 22, 2014 at 03:45 PM 0
Share

@Jagster $$anonymous$$ark the line with the problem in the Code itself. Also, please post the full error from the console window.

avatar image Jagster · Dec 22, 2014 at 03:51 PM 0
Share

right theres the error its outputting but im still not sure why the game is functioning perfectly as intended

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Error putting an object into an Array 0 Answers

NullReferenceException Error 6 Answers

SetActive is giving me a lot of issues 2 Answers

NullReferenceException: Object reference not set to an instance of an object 1 Answer

Object reference not set to an instance of an object. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges