Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by GJMartinez · May 22, 2016 at 02:30 AM · scripting problemobjectreferenceinstance

How to Fix this issue

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections.Generic;
 
 public class ObjectiveList : MonoBehaviour {
     
     public ObjectiveList obj;
     public Text objList;
     public List<Objective> objectives = new List<Objective>();
 
     void Start() {
         obj = FindObjectOfType<ObjectiveList>();
         obj.CreateObjective ("obj1", "Enter the palace.");
     }        
 
     void OnTriggerEnter(Collider other)
     {
         if (other.tag == "Player") {
             obj.CompleteObjective ("Obj1");
         }
     }
 
     void Update()
     {
         objList.text = "";
 
         Objective[] objArray = objectives.ToArray();
 
         for (int i=0; i < objectives.Count; i++)
         {
             Objective test = objectives[i];
 
             if(!test.completed)
                 objList.text += (i+1)+ "." + objArray[i].objective + "\n";
             else
                 objList.text += (i + 1) + ".<b><color=green>" + objArray[i].objective + "</color></b>\n";
         }
     }
 
     public void CreateObjective(string shortName, string objText)
     {
         objectives.Add(new Objective(shortName, objText, false));
         objectives.Sort();
     }
 
     public void CompleteObjective(string objName)
     {
         Objective selected = objectives.Find(x => x.identifier.Contains(objName));
         selected.completed = true;
     }
 
     public void RemoveObjective(string objName)
     {
         objectives.Remove(objectives.Find(x => x.identifier.Contains(objName)));
     }
 }
 

NullReferenceException: Object reference not set to an instance on an object ObjectiveList.Update () (at Assets/ASCore/Scripts/ObjectiveList.cs:25

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TBruce · May 22, 2016 at 02:37 AM

When posting code, please do not post screen shots. People can not help much that way. Please format ALL you code properly and paste the code directly into the body of the question. To do that copy the code to your clipboard and press the "101010" button in the toolbar of the UA text editor. This will format the code so it can be easily read in the forum.

But I would say your problem is that

 public text objList;

has not been set in the inspector and therefore is null. so when you go to use is you will get a NullReferenceException error.

Comment
Add comment · Show 2 · Share
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 GJMartinez · May 22, 2016 at 03:32 AM 0
Share

@$$anonymous$$avina How can I set it into the inspector to fix this problem?

avatar image TBruce GJMartinez · May 22, 2016 at 04:03 AM 0
Share

You need to create a UI Text object in the hierarchy like seen in this link. Then drag the UI Text object to the Text field as seen in this link.

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

62 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

CameraController (object reference not set to an instance of an object) 1 Answer

Object reference not set to an instance of an object [problem with Unity 5] 2 Answers

MonoDevelop Unity API reference function with wrong path. How to Fix it? 1 Answer

Can't access a method from another script (Object reference not set to an instance of an object) 1 Answer

NullReferenceException: Object reference not set to an instance of an object 3 Answers


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