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 Sendatsu_Yoshimitsu · Nov 24, 2017 at 05:17 PM · cameranullreference

Why does checking if Camera.Main is non-null generate an assertion failed message?

I'm trying to add a line in my character controller that checks if the main camera exists, and turns the character relative to that camera:

 bool relativeToCamera = true;
 if (relativeToCamera && Camera.main !=null)
         {
             relativeTransform = Camera.main.transform;
         }

This works fine while in-game, but every time I quit out of play mode, I get two identical errors pointing at this line: Assertion failed: Assertion failed on expression: 'go.IsActive() && go.GetTag() != 0' UnityEngine.Camera:get_main()

It specifically points to my conditional check, not the line setting the relative transform, which makes me think that checking if Camera.main !=null is the problem. However, the act of checking whether something is null shouldn't cause any problems, it's only trying to access it that would be an issue. Is there something I can change here, or is this one of Unity's harmless eccentricities?

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 Glurth · Nov 24, 2017 at 06:14 PM 0
Share

I would suggest you try reproducing this issue an otherwise blank project. If you are able to do this, I would suggest submitting it as a bug.

1 Reply

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

Answer by Legend_Bacon · Nov 24, 2017 at 05:39 PM

Hello there,

When you type in "Camera.main", I'm guessing Unity searches for a Camera with the "main" tag. But you can't get the tag of a GameObject that's inactive, so it gives you an error. Since this only happens when quitting play mode, I am guessing you have that line in an Update loop or OnDestroy call?

An easy fix would be to assign a Camera variable on Start() to "Camera.main", and then just check if that variable is null or not. That should fix it, but if it doesn't please let me know.

Hope that helps!

~LegendBacon

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 Sendatsu_Yoshimitsu · Nov 24, 2017 at 06:29 PM 0
Share

Outstanding, that works! Thank you :)

avatar image Glurth · Nov 24, 2017 at 06:35 PM 1
Share

Note: This will work only if you don't change the main camera. (unusual, but can happen)

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

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

Related Questions

How to make camera position relative to a specific target. 1 Answer

How can I produce the typical FPS mouse steering effect? 2 Answers

Show other players other models 1 Answer

This camera controller is overriding it's default position when the boundary check is enabled? 0 Answers

How to create texture from multiple sprite in unity2d? 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