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 Pengawk · Feb 18, 2016 at 02:29 AM · c#nullreferenceexceptionexceptionnull reference exception

Faulty NullReferenceException?

I'm working on a music-based project and am trying to do the following initialization:

         int currentFrame = rhythmTool.CurrentFrame;

And whenever I run my project, Unity throws an exception pointing directly to that line (it's the first line in Update()) and noting it as "NullReferenceException".

This happened only after Unity encountered a "fatal error" and had to be force-closed.

Comment
Add comment · Show 1
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 EmHuynh · Feb 18, 2016 at 02:50 AM 0
Share

Hello, @Pengawk. For us to definitely resolve this problem, please copy and paste the script that contains this problem. Thanks!

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by jellythedonut · Feb 18, 2016 at 03:08 AM

A NullReferenceException typically refers to you trying to access a value which does not exist. So, for instance if you created an object and tried to get that object's value, but the object is not initialized, you'd get this exception. I am fairly certain that in the context of you question, this means that you didn't initialize the "rhythmTool". Do you have something like that sets the rhythmTool equal to something in your Start method?

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
avatar image
0

Answer by EmHuynh · Feb 18, 2016 at 03:22 AM

Hi, @Pengawk. The problem is caused by not initializing rhythmTool. You can set it by using the inspector (if its access modifier is public) or you can initialize it in the Start function. There is not enough information regarding rhythmTool, so this answer might not accurately solve the problem. However, by researching, I assume you are using RhythmTool. I found a documentation for it.

To solve this issue, initialize rhythmTool:

 public RhytmTool rhythmTool; // Can be set in the inspector by selecting a RhythmTool component.
 
 void Start() {
     // Initialize rhythmTool by getting the RhythmTool component of this object.
     rhythmTool = GetComponent< RhythmTool >();
 }

If the initialization of rhythmTool failed, it is usually because GetComponent could not find a RhythmTool component.

Comment
Add comment · Show 4 · 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 Pengawk · Feb 18, 2016 at 04:02 AM 0
Share

I already have that in place.

     public class BasicController : $$anonymous$$onoBehaviour
     {
     
         public RhythmTool rhythmTool;
         public AudioClip audioClip;
         Analysis mid;
         public GameObject arrowUp;
         Vector3 moveUp;
         bool isCreated;
     
         // Use this for initialization
         void Start ()
         {
             rhythmTool = GetComponent<RhythmTool>();
             rhythmTool.NewSong(audioClip);
             mid = rhythmTool.$$anonymous$$id;
             moveUp = new Vector3(0.65F, 5, 0);
             isCreated = true;
         }

Where the GameObject arrowUp is being assigned within Unity in the Inspector.

avatar image EmHuynh Pengawk · Feb 18, 2016 at 07:10 AM 0
Share

Hello, @Pengawk. Is there a RhythmTool component attached to the same game object as the BasicController script?

avatar image Pengawk EmHuynh · Feb 18, 2016 at 07:15 AM 0
Share

Indeed there is. I figured it out just a few moments ago. It had something to do with Unity and Visual Studio not cooperating after Unity crashed completely.

Show more comments

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

104 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Having a issue with a NullReferenceException 1 Answer

Using TextMeshProUGUI variable in a static function is returning a NullReferenceException 0 Answers

List remains null after initialisation? 1 Answer

Null Reference in UnityStandardAssets.Utility.WaypointProgressTracker.Update 0 Answers

NullReferenceException when attempting to call a GameObject from within PointerEventData 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