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
1
Question by felixfaire · Jul 04, 2018 at 12:27 PM · camerarenderingorder-of-executiondrawmesh

Why is OnRenderObject() called after OnPostRender()??

There must be a reason for this but it seems very counterintuitive. After a while investigating this the debug output clearly shows that a Camera's OnPostRender() is called before OnRenderObject() with that camera. From several tests this seems to be the behaviour.

Camera1 calls OnPreCull() etc
Camera1 calls OnPostRender()

Object1 OnRenderObject() gets called some time later with Camera1 as current camera..

The documentation is not clear on this either stating:

OnRenderObject: Called after all regular scene rendering is done.
OnPostRender: Called after a camera finishes rendering the scene.


It is unclear what being called "after other rendering is done" and "after the camera finishes" means in this context.

I dont know if this is a bug, bad documentation or just bad design (or i've potentially deeply misunderstood something) but I can someone please help me find a function such as OnPostRender() on a Camera that is actually called after it has finished everything? (including custom meshes and procedural objects). My camera puts some specific objects onto a layer before rendering (so only they are rendered by the camera) and is supposed to put the objects layer back to default in OnPostRender() AFTER rendering them, however the above 'quirk' means this doesnt apply to Graphics.DrawProcedural objects etc. as their layers are reset before they get to be rendered

If anyone has any (not too hacky) workarounds for this they would be much appreciated.

Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mptp · Aug 06, 2018 at 04:24 AM

OnRenderObject and OnPostRender are (from what I understand) more or less the same thing, except OnRenderObject can go on any GameObject, while OnPostRender has to go on a GameObject with a Camera component.

The way I read that is that you can't rely on them having a particular order. I definitely agree it's counterintuitive.

An easy workaround is to use WiatForEndOfFrame() - put whatever you want to do in a method that you call like this:

 void OnEnable() {
     StartCoroutine(WaitRoutine());
 }
 
 void OnDisable() {
     StopAllCoroutines();
     //or use a reference to it if you want others to keep going or whatever
 }
 
 IEnumerator WaitRoutine() {
     while(true) {
         yield return new WaitForEndOfFrame();
         DrawLast();
     }
 }
 
 void DrawLast() {
     //do your drawing in here - it will happen *after* all OnPostRender and OnRenderObject executions :)
 }
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

143 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 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

Render object with different shader depending on the camera 2 Answers

Improve render quality? 0 Answers

Bad rendering? 1 Answer

Frustum culling doubt 2 Answers

Render everything in black, but the enemies in red 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