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 /
avatar image
0
Question by CryFan001 · Dec 23, 2018 at 05:07 AM · exceptionexceptionsunassignedreferenceexceptunassigned

UnassignedReferenceException

Hi! So I'm trying to make a quest for the player and wrote the following code:

 // Applied to Quest NPC
 public class Quest001 : MonoBehaviour
 {
  
     public string questName = "Coin Collect";
 
     public string questInfo = "Collect all the coins";
 
     public float range = 3f;
 
     public Transform player;

     // I need this to set the questText to active
     public GameObject questPanel;

     // The text object to holder the questInfo
     public Text questText;

     // Same purpose like the two above
     public GameObject activeQuestPanel;
     public Text activeQuestText;
 
     void Start()
     {
         questText.text = questInfo;
         activeQuestText.text = "Active quest: " + questName;
     }
 
     void Update()
     {
         RaycastHit hit;
 
         if (Input.GetMouseButtonDown(2) && Physics.Raycast(player.position, player.forward, out hit))
         {
             if (hit.distance <= range)
             {
                 questPanel.SetActive(true);
                 activeQuestPanel.SetActive(true);
             }
         }
     }
 }


I assigned all of the value in like so: alt text

But when I play my game, it's saying "UnassignedReferenceException: The variable player of Quest001 has not been assigned" but I can play my game fine, it works. But this exception kept showing on the console window.

Is it a bug or I did something wrong?

Note: The two text variable in the image is not the same Text.

Thanks alot! I appreciate it!

bug.png (13.7 kB)
Comment
Add comment · Show 3
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 hexagonius · Dec 23, 2018 at 09:04 AM 0
Share

the player either gets destroyed somewhere (and replaced with a new one so you did not notice).
this code is not doing that

avatar image CryFan001 · Dec 23, 2018 at 10:36 PM 0
Share

@hexagonius Wehn I play my game, it does give me an error but I can play it O$$anonymous$$ like it was some sort of bug or something. I'm very sorry to not mention that.

avatar image hexagonius CryFan001 · Dec 23, 2018 at 10:42 PM 0
Share

ok, try to be more clear. it does not make sense at all. the player is accessed in update so you should be spammed. apparently you're seeing the error, what, once?
which line?
my first question would be, how dots the variable recover from null?
and check out using logs and breakpoints as those are key to finding causes yourself.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Sakeus · Dec 23, 2018 at 02:57 PM

It seems to me that "Player" may have been unassigned during runtime by another script, try making player private and serialize it. There's is nothing in your provided script that should cause this error.

  [SerializeField]
     private Transform player;
Comment
Add comment · 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

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

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

We get this "TypeLoadException: Could not load type UnityEngine.UI." after every compile 0 Answers

Exceptions When Changing Scenes 2 Answers

No line numbers in stack trace 1 Answer

How to access variable from another c# script file? 1 Answer

Unassigned Reference Exception error? 4 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