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 /
This question was closed Jul 16, 2018 at 09:30 AM by J-F for the following reason:

Issue was solved by reimporting assets.

avatar image
0
Question by J-F · Jul 16, 2018 at 08:28 AM · namespacenull reference exceptionstatic-function

Null reference exception with static method

My static method that i've set within an abstract class using a custom namespace keeps giving me a null reference exception when i try to pass a Vector3 to it.

 using UnityEngine;
 
 namespace DebugUtility
 {
     public class DebugUtility
     {
         public static void DisplayInfo(Vector3 pos, string info)
         {
             Vector3 pointOnScreen = Camera.main.WorldToScreenPoint(pos);
             //rest of the code
         }
     }
 }

I call it with: DebugUtility.DebugUtility.DisplayInfo(Vector3.zero,text);

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 Stratosome · Jul 16, 2018 at 08:35 AM 0
Share

I just tried that exact code and it works for me. No null reference exceptions... I used a hard-coded string for your 'text' variable though, but I don't see why that would make a difference. What line of code is the error pointing at?

2 Replies

  • Sort: 
avatar image
0

Answer by Bunny83 · Jul 16, 2018 at 08:57 AM

Well, possible reasons are:


Camera.main:

The first enabled camera tagged "MainCamera" (Read Only).

The primary Camera in the scene. Returns null if there is no such camera in the scene. This property uses FindGameObjectsWithTag internally and doesn't cache the result. It is advised to cache the return value of Camera.main if it is used multiple times per frame.


The second possible reason is this

 //rest of the code


I think you should be more specific here. If you get a NullRef exception you get a stacktrace with line numbers. You haven't provided any. Finally from the code we see it's also possible that your info string is null. However we do not know if and how you may use it inside your method and we do not know where text is coming from.


In short:

This question can not be answered.

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 J-F · Jul 16, 2018 at 09:29 AM

I have a main camera tagged as the default mainCamera. I don't know what the issue here was, but i reimported all assets and its seems to have fixed the issue.

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 Stratosome · Jul 16, 2018 at 09:30 AM 0
Share

Hmm, well, glad it is all fixed at least!

Follow this Question

Answers Answers and Comments

88 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

Related Questions

Which namespaces are supported in each platform? 1 Answer

private void GenerateUV (Decal) {The type or namespace 'Decal could not be found (are you missing a using directive or an assembley referance?) 0 Answers

Can't use Namespaces with Mono and 1 class 1 namespace file 1 Answer

CSharpMsgrExtended: CS0246: The type or namespace name `Exception' could not be found. 2 Answers

Im a beginner of Soomla, I have a lot of question:what to do next after creating my counter part of the MuffinRushAssets.cs? 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