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
-1
Question by DGArtistsInc · Dec 03, 2011 at 10:45 PM · cameragameobjectenabled

gameObject.enabled not working

So i am making a script that allows me to cycle through two cameras when i press tab. There is a first person and third person camera. Which are defined in variables in the script. Ex. my variable is thirdPersonCamera and the line of code is

 thirdPersonCamera.enabled = true;

Is there something wrong with this? Because the error message is

MissingFieldException: Field 'UnityEngine.GameObject.enabled' not found.

Any help is appreciated thank you.

Comment
Add comment · Show 7
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 syclamoth · Dec 03, 2011 at 11:19 PM 0
Share

Turn that into an answer, since that's what it is!

avatar image DGArtistsInc · Dec 04, 2011 at 12:04 AM 0
Share

but i have two cameras so setting it to a camera ins$$anonymous$$d of a gameObject wouldn't work. Also when i set things to active ins$$anonymous$$d of enabled there is no error, however when i press tab the thirdPersinCamera does not turn on or off same goes for the firstPersonCamera so therefore it doesnt switch cameras

avatar image dannyskim · Dec 04, 2011 at 03:15 AM 0
Share

I think you're misunderstanding Camera variable declarations. Technically, a camera IS a GameObject, you're assu$$anonymous$$g that each camera when declared is going to be labeled as the 'main' camera, which is not true. I suggest you read through the Camera part of the Unity Scripting documentation to get a better understanding of how switching between cameras works.

avatar image syclamoth · Dec 04, 2011 at 06:34 AM 0
Share

Not quite how I'd explain it. A Camera is not a gameObject, however every camera is attached to a gameObject. The camera is the component that does all the rendering, however the gameObject itself still exists. In any case, it's definitely more appropriate to use a Camera type variable in this case, since we're talking about cameras here, not gameObjects.

avatar image dannyskim · Dec 04, 2011 at 07:28 AM 0
Share

Thanks syclamoth for clarifying that.

Show more comments

2 Replies

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

Answer by dannyskim · Dec 04, 2011 at 06:12 AM

The error explains it all. There is no 'enabled' variable that is associated with a Game Object. What you're most likely thinking of is 'active' when you are accessing a Game Object directly. So what you're most likely looking for is " thirdPersonCamera.active = true; ". Camera's do have an 'enabled' variable, and the reason why you're most likely not getting access to it ( i'm guessing ) is that you're declaring the camera as a GameObject when it needs to be declared as a Camera in your variable declarations. Otherwise, enabled would work.

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 FLASHDENMARK · Dec 04, 2011 at 07:56 AM 0
Share

Nice copy and paste.

avatar image dannyskim · Dec 04, 2011 at 07:59 AM 0
Share

I meant to delete my comment from above to re-post as an answer. Don't see harm in copying and pasting my own words if you were insinuating plagiarism.

avatar image FLASHDENMARK · Dec 04, 2011 at 08:15 AM 0
Share

No, I didn't mean anything bad when I said it. I was for fun.

avatar image dannyskim · Dec 04, 2011 at 08:44 AM 1
Share

does not compute.

avatar image
3

Answer by Draze · Aug 06, 2015 at 11:10 PM

For any future readers as of Unity 5 gameObject.active = true; is depricated. This is now called SetActive(true)

C#:

 gameObject.SetActive(true);



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 eberperetto · Oct 01, 2015 at 06:00 AM 0
Share

I've just opened an old project here and there are 90 errors like these. I think that ignoring the warnings while developing in Unity 4 was not a good idea :( Thanks for the comment here!

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

If i disable a GameObject does all it's components get disabled also? 2 Answers

Rotating GameObject Around Player With "Mouse Y" Position 2 Answers

How to create a new camera and NOT have it own the view (but still Find-able)? 1 Answer

Unity3D scene not rendering objects in Game screen 3 Answers

Set Game Object Position to Sides of a Camera 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