• 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
1
Question by J3-Gaming · Jul 26, 2011 at 02:52 PM · nullreferenceexception

Rethrow as TypeInitializationException

First of all, ill give you all the runtime error:

 NullReferenceException
 PlumberAnimation..cctor ()
 Rethrow as TypeInitializationException: An exception was thrown by the type initializer for PlumberAnimation

PlumberAnimation is a static class that I call static methods from, nothing fancy. This code has always worked, and even svn revert to my old code will still break it (I think I may have touched a unity setting)

 // Plumber.cs
 // not a static class
 public void Awake()
 {
     PlumberAnimation.Awake();
 
 } // CRASHES HERE, The compiler thinks it crashes on the end bracket... wtf?

 // PlumberAnimation.cs
 // static class
 public static void Awake()
 {
 //even with nothing in here, it crashes
 }
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 J3-Gaming · Jul 26, 2011 at 02:57 PM 0
Share

oh and try{}catch{} only works once, then its like it loops to try again and continues to crash. I get the exception messages spammed in my console output.

1 Reply

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

Answer by J3-Gaming · Jul 26, 2011 at 04:06 PM

\ Fixed /

In my static class this was declared at the top:

private static Plumber plumber = GameObject.FindGameObjectWithTag("Plumber").GetComponent(typeof(Plumber)) as Plumber;

No object had that tag so the first call returned null - crashing the class compiling. This meant the class was no longer valid, but still allowed code execution to continue.

Comment
Add comment · Show 1 · 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 swatmaster69 · Mar 24, 2013 at 09:42 PM 0
Share

Thanks. I had the same problem, but I had to see this answer several times before I "got" it. $$anonymous$$y problem and answer is here if anyone needs a slightly different description of what was going on.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Return value inexplicably becomes null 1 Answer

Why am I getting a NullReferenceException while trying to set a Sprite? (C#) 2 Answers

Why am i getting a NullReferenceException when i switch platform to Android? 0 Answers

Why am I getting this Null Reference Exception in the new Unity update. 1 Answer

Checking for null against Texture2D 0 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