Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 DottoraQN · Apr 17, 2013 at 09:45 PM · c#animationcamera

Unassigned Reference Exception

I have been getting this error when I try to run my code for switching cameras. I don't understand why it is telling my that the variables are null, as I have other variables assigned similarly.

"UnassignedReferenceException: The variable CutSceneCam of 'UponCollision' has not been assigned. You probably need to assign the CutSceneCam variable of the UponCollision script in the inspector."

Here is the code that I am using:

 public class UponCollision : MonoBehaviour {
     public Camera CutSceneCam;
     public Camera MainCamera;
      
     void Start (){
         CutSceneCam.enabled = true;
         MainCamera.enabled = false;
     }
      
     void OnTriggerEnter(Collider col){
         if (col.gameObject.name == "CutSceneCam") {
             CutSceneCam.enabled = !CutSceneCam.enabled;
             MainCamera.enabled = !MainCamera.enabled;
         }
     }
 }
Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dracorat · Apr 17, 2013 at 09:46 PM

You need to look at this object in Unity and then look to the right where you placed your script file. This area is called the inspector.

There, the script will have two spots for your two public variables - "CutSceneCam" and "MainCamera".

You need to drag a camera object in to each to assign them.

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 DottoraQN · Apr 18, 2013 at 12:05 AM 0
Share

I've done that, but for some reason, it likes to add a second script to the object that I applied the script to. Adding the objects to the second script fixed the error, however now I need to get my animations working. Thanks for the help.

avatar image Bitpocketer · May 02, 2015 at 07:48 PM 0
Share

How did you do it?I'm having exactly the same problem, you mean i should add another script to the Gameobject and have my variables in that script and retrieve from it into the one where it's causing problem?

avatar image
0

Answer by DottoraQN · Apr 18, 2013 at 08:02 PM

Another problem has presented itself. The code now works, the animation works, but when the camera colides with the trigger box that I have, it doesn't switch from the stationary camera to the player camera. The code is the exact same, except for the fact that the object that is supposed to be colliding with the collider has changed several times in experimentation. At the moment, I have a sphere running into a box collider, and this is supposed to switch the cameras, but it doesn't.

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 Dracorat · Apr 18, 2013 at 08:12 PM 0
Share

This should be a comment, not an answer.

At any rate, double check you didn't put the same camera on both spots, that the cameras aren't overlapping and that you didn't put the wrong script object on the wrong objects.

avatar image
0

Answer by LDpro · Sep 01, 2018 at 05:09 PM

what I have done to rectify this issue was copy my c# script that I coded in Monodevelop delete the C# file .. re-create the C# file - copy the script back into the C# file again attach the variable or objects back into the script in the inspector and the run the project again.

what I remember was that the first time around I ran the scene before I attached the objects to the script. Upon stopping the game then attaching the objects after I realized they were missing I received this error. I figured Unity held some sort o memory that the objects were missing script so I figured I would make sure everything was in place before I hit the play button/ran the game this time around. Seems to work now. even though I get an error that the second object is now missing.

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 LDpro · Sep 01, 2018 at 05:12 PM 0
Share

the 2nd error was due to a blank script I inadvertently attached to the 2nd object. Once I removed this empty script the warning went away.

avatar image
0

Answer by mrwolfclawz · Aug 04, 2020 at 10:22 AM

I have a strange problem that the camera un-assigns itself as soon as I play, when I stop it re-assigns... I have no clue whats happening.

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

14 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

Related Questions

Smooth transition from Camera1 to Camera2? 1 Answer

How to create an animation hands (or script) to pick-up a cup from the table in 3ds max or maya or from direct unity! Please help!! 2 Answers

Animated Texture Offset 1 Answer

adding animation dynamically by script 0 Answers

Playing an animation with C#? 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