• 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
Question by nyahoon · Apr 04, 2017 at 10:30 PM · camerarenderingrendertexture

How to call Camera.Render from Update

Hi,

From Unity 5.6, I got the following error when Camera.Render() is called in Update() function:

Rendering camera 'DrawSomethingToRenderTexture', but calling code does not set it up as current camera (current camera: 'Main Camera') UnityEngine.Camera:Render()

I noticed that Camera has SetCurrent(Camera) static function, but this function did not help.

Is there any way to remove this error? Or, Camera.Render() should not be called in Update function? I need to call it in Update function to see a rendered texture in Editor. The script has "ExecuteInEditMode" attribute but camera events such as OnPostRender are not called in edit mode. So, I had to manually call Camera.Render() in Update function which will be called in edit mode.

Thanks

Comment

People who like this

0 Show 0
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

1 Reply

  • Sort: 
avatar image

Answer by Bunny83 · Apr 04, 2017 at 10:54 PM

Camera.Render directly renders that camera. It should not be called from Update. While the Update methods are called the rendering engine is not "active".

Have a look at the flowchart in the docs. From there you should call Render() highly depends on the reason why you want to render the camera manually.

If you want to render the camera after all enabled cameras has been rendered you may want to use a coroutine with WaitForEndOfFrame or simply render it during the Repaint event in OnGUI.

Comment
nyahoon
firatlahur

People who like this

2 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 nyahoon · Apr 06, 2017 at 03:13 PM 0
Share

Thanks for the reply. That makes sense, but I still got the same error.

I would like to call Camera.Render() between user input in edit mode and Scene View rendering though, I tried OnDrawGizmos, OnGUI, and WaitForEndOfFrame. (OnGUI and WaitForEndOfFrame were not called unless Game View is visible)

I feel like it is a bug of Unity now. If the scene has one object that calls Camera.Render, I got this error:

Rendering camera 'DrawSomethingToRenderTexture', but calling code does not set it up as current camera (current camera: 'Main Camera') UnityEngine.Camera:Render()

And if the scene has two objects, I got this:

Rendering camera 'DrawSomethingToRenderTexture1', but calling code does not set it up as current camera (current camera: 'DrawSomethingToRenderTexture2') UnityEngine.Camera:Render() Rendering camera 'DrawSomethingToRenderTexture2', but calling code does not set it up as current camera (current camera: 'DrawSomethingToRenderTexture1') UnityEngine.Camera:Render()

I don't know why the current camera at the first error is not Main Camera but DrawSomethingToRenderTexture2, it seems like the current camera remains after Camera.Render finished.

avatar image meat5000 nyahoon · Apr 06, 2017 at 03:13 PM 0
Share

please dont post comments as answers

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

RenderTexture captured from camera with post effects only shows the emission pass. 1 Answer

How can I set the exact camera render size for render textures? 0 Answers

RenderTexture.Create failed: format unsupported 0 Answers

Render a camera multiple times in a single frame? 1 Answer

Rendering a Pygame surface in Unity 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