- Home /
OnpostRender is not called
Hi, i have this script attached to my camera:
public class Test : MonoBehaviour {
private void OnPostRender()
{
Debug.Log("ok");
}
}
But Nothing get debugged, i don't anderstand why. Everything is of course enabled, and just one camera in my scene.
Edit: I found that it works if i set no render pipeline in graphics settings. But i need it for shadergraphs!
Are you sure the script is attached on the CA$$anonymous$$ERA?
$$anonymous$$onoBehaviour.OnPostRender()
Description
OnPostRender is called after a camera finished rendering the scene.
This function is called only if the script is attached to the camera and is enabled.
Yes i am. And when i set no render pipeline in graphics settings, it's calling. But if i set a LWRP it dosen't. I'm looking for why, but i find nothing related with renderPipelines and OnPostRender function
It seems like the error has been reported to Unity :
https://forum.unity.com/threads/feedback-wanted-lightweight-render-pipeline.518267#post-3397752
A dev wrote here: https://forum.unity.com/threads/feedback-wanted-scriptable-render-pipelines.470095/page-8
Removing Camera Rendering Callbacks As pre-SRP Unity stands there are a number of callbacks issued to sibling scripts of a Camera component; specifically:
OnPreCull
OnPreRender
OnPostRender
OnRenderImage
As these callbacks stand they offer ways to inject extra rendering code into Unity. The issue that arises when attempting to port these to SRP world is multifaceted.
Answer by arminelec · Sep 09, 2018 at 04:28 PM
Update (2020-02-10):
The new SRP ( URP
and HDRP
) system is no longer experimental, so I thought I would update my answer for anyone still interested in this matter. In this update I am using RenderPipelineManager
instead of RenderPipeline
and included the comments from the previous reply into account. (To see the original answer, please use the gear icon -> revision history).
using UnityEngine;
using UnityEngine.Rendering;
public class MyClass: MonoBehaviour
{
void OnEnable()
{
RenderPipelineManager.endCameraRendering += RenderPipelineManager_endCameraRendering;
}
void OnDisable()
{
RenderPipelineManager.endCameraRendering -= RenderPipelineManager_endCameraRendering;
}
private void RenderPipelineManager_endCameraRendering(ScriptableRenderContext context, Camera camera)
{
OnPostRender();
}
private void OnPostRender()
{
// Your already existing code
}
}
Comment to the previous version of answer: As far as I know, equivalent of OnPostRender in SRP is RenderPipeline$$anonymous$$anager.endCameraRendering
using UnityEngine.Rendering
Points to the right direction, but the correct answer should use the event described by @RunninglVlan.
The gear icon is on the right hand side of the title of any answer in Unity forums. It is visible when logged in and clicking it shows a menu. If you click it and only see a "Report" option, then it means that I made a mistake (and the revision history is only visible to me). In that case, I will update my answer and will remove the sentence about the old answer.
I don't know if they Unity changed something, but the gear icon and revision history is now only available to the original poster. Unity still hasn't officially deprecated the OnPostRender function, despite it no longer being called if you ever so much as poke at the post processing stack, and this thread now comes up at the top of searches for this issue. Would you be able to re-add your alternate solutions back into the main post to help people like me stuck in limbo between the old render pipeline and srp?
Answer by ju_my · Nov 20, 2018 at 01:40 PM
Thanks you very much, it seems to work! But GL.Lines are not rendering
Answer by BahamutGundam · Jul 16, 2019 at 02:22 AM
RenderPipeline.beginCameraRendering() is also an alternative.
Unlike RenderPipeline.beginFrameRendering() which receives Camera[] as parameters, RenderPipeline.beginCameraRendering() only receives one Camera object as a parameter, and therefore you can check which camera you would like to apply your code onto.
Answer by ccvannorman · Jun 18, 2020 at 06:20 PM
Can you please explain how to get GL Lines to show up for Oculus Quest? I do not understand what you mean by this statement
..
"RenderPipeline.beginCameraRendering() only receives one Camera object as a parameter, and therefore you can check which camera you would like to apply your code onto."
..
Is there specific code which you can share which gets GL LInes to show up for Camera.main in Quest?
You're asking a question in your answer. This is not how it works. If you have a comment to somebody's answer, click on Add comment under that answer. But you're mentioning Oculus Quest here, which original question wasn't about, so I think it's better to Create a new question by clicking on Ask a question mentioning your problem.
But you're mentioning Oculus Quest here, which original question wasn't about, so I think it's better to Create a new question by clicking on Ask a question mentioning your problem.
I agree with this.
Anyways, to answer the question, my comment on "RenderPipeline.beginCameraRendering()" is about it being an alternative of "OnPostRender()", which is what the original question asked. It is not necessarily related to GL Lines, nor Oculus Quest.
Your answer
Follow this Question
Related Questions
3D Objects are not being in their regular shape at distance 2 Answers
Best way to access RenderTexture immediately after camera render 0 Answers
Capture a Screenshot Through a Camera in the Lightweight Render Pipeline 1 Answer
Canvas Rendering Execution Order Question 0 Answers
Unity - Render XR game objects onto processed camera image 0 Answers