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 Seith · Mar 13, 2013 at 12:03 PM · cameraeditorscene

Problem accessing the scene camera

Hello, I'm trying to access the editor's camera (also known as Scene Camera) through this simple code in an AWAKE() function:

 Debug.Log("Camera.current = " + Camera.current);


... But it always returns "null", even though the scene camera panel is selected when I start the game through CTRL+P. Is that a known Unity bug or am doing something wrong?

Comment
Add comment · Show 2
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 GuyTidhar · Mar 13, 2013 at 12:26 PM 1
Share

Are you following unity's guideline to only use it for low rendering?

(http://docs.unity3d.com/Documentation/ScriptReference/Camera-current.html)

If not, I'll advise you to try and work with Camera.main

avatar image Seith · Mar 13, 2013 at 12:38 PM 0
Share

Well if I'm not mistaken, using Camera.main would get me the in-game player camera. Ins$$anonymous$$d, what I need is to get the scene camera's position and orientation as the game starts, so I can adjust my player camera accordingly.

What would be the correct method to do this, please?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GuyTidhar · Mar 13, 2013 at 12:45 PM

  1. Your scene camera can be your game camera and you can mark it as the main camera by changing the 'tag' to 'MainCamera'.

  2. Or a script attached to your player camera can have a public variable of type 'Camera' to which you drag the scene camera and from which you access it:

e.g.

 var mainCam : Camera; // Drag the scene camera to this exposed variable once you attach this sctipt to the player camera
 
 void Start()
 {
   transform.position = mainCam.position;
   transform.rotation = mainCam.rotation;
 }
Comment
Add comment · Show 3 · 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 Seith · Mar 13, 2013 at 01:00 PM 0
Share

Ah, forgive me but I don't even know how to see (or select) the Editor Scene camera in the hierarchy panel. The only camera in there is my in-game camera, which is indeed tagged as "$$anonymous$$ainCamera".

And I'm confused by your saying that "my scene camera can be my game camera". So far I have only one camera for my game (my "player camera"), which is visible and selectable in the hierarchy panel. But there is obviously also the default Unity in-editor scene camera (which again is invisible/un-selectable in the hierarchy panel). And THAT is the camera I'm interested in. Am I missing something here?

avatar image GuyTidhar · Mar 13, 2013 at 01:12 PM 0
Share

I see, my bad. I regarded the 'scene camera' you've mentioned as the default camera you get when creating a scene.

In this case, I am not aware of built in way to access this data.

But what are you trying to achieve by doing so?

avatar image Seith · Mar 13, 2013 at 01:24 PM 0
Share

I would like to use the editor scene camera to quickly go anywhere I please in my level, and then jump in-game; my player control script would then adjust the player's position to match the editor scene camera's position.

So in effect, the player would spawn wherever the editor scene camera is located, roughly matching its position and orientation.

The CryEngine works a bit like that. I mean you can have your standard player start spawn point of course, but you can also just jump in-game anywhere anytime. It's a great workflow. Very flexible. One that could easily be implemented in Unity if the editor camera could be queried for its world transform information.

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

11 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

Related Questions

Drawing Handles 1 Answer

Camera Zoom in Scene View 1 Answer

Scene View camera clipping 1 Answer

Setting the SceneView View Angle/Position? 1 Answer

Camera behavior the same as the unity editor has 2 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