Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

OnPreCull event not running

Discussion in 'Scripting' started by Stroustrup, Jun 8, 2020.

  1. Stroustrup

    Stroustrup

    Joined:
    May 18, 2020
    Posts:
    142
    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour
    2. {
    3.     private void OnPreCull() {
    4.         Debug.Log("running");
    5.     }
    6. }
    console never outputs "running"

    any ideas as to why? shouldn't it output every frame?

     

    Attached Files:

  2. Stroustrup

    Stroustrup

    Joined:
    May 18, 2020
    Posts:
    142
    seems on pre cull doesn't at all work with either hdrp or urp, any alternatives?
     
  3. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,595
    You can add a Monobehaviour on a camera with something like this in it

    Code (CSharp):
    1. [RequireComponent(typeof(Camera))]
    2.     [ExecuteInEditMode]
    3.     public class CameraMirror : MonoBehaviour
    4.     {
    5.         new Camera camera;
    6.        
    7.         void Awake()
    8.         {
    9.             camera = GetComponent<Camera>();
    10.  
    11.             RenderPipelineManager.beginCameraRendering += (context, camera) =>
    12.             {
    13.                 onBeginCameraRender();
    14.             };
    15.  
    16.             RenderPipelineManager.beginFrameRendering += (context, camera) =>
    17.             {
    18.                 onBeginFrameRendering();
    19.             };
    20.  
    21.             RenderPipelineManager.endCameraRendering += (context, camera) =>
    22.             {
    23.                 onEndCameraRendering();
    24.             };
    25.         }
    26.  
    27.         void onBeginCameraRender()
    28.         {
    29.             //add your code here
    30.         }
    31.  
    32.         void onBeginFrameRendering()
    33.         {
    34.             //add your code here
    35.         }
    36.  
    37.         void onEndCameraRendering()
    38.         {
    39.             //add your code here
    40.         }
    41.     }
     
    andreiagmu, pierre92nicot and Bunny83 like this.