Closed orangeagain closed 3 years ago
On what platform? On Android, I consistently get this ordering (which is what I would expect):
OnARCameraFrameReceived
Update
OnBeforeRender
OnRenderImage
In the Editor, I get the same ordering of OnBeforeRender
and OnRenderImage
.
This is my test script:
using UnityEngine;
using UnityEngine.XR.ARFoundation;
[RequireComponent(typeof(Camera))]
[RequireComponent(typeof(ARCameraManager))]
public class EventOrdering : MonoBehaviour
{
void Start()
{
Application.onBeforeRender += OnBeforeRender;
GetComponent<ARCameraManager>().frameReceived += OnARCameraFrameReceived;
}
void Update() => Debug.Log($"{Time.frameCount}: {nameof(Update)}");
void OnRenderImage(RenderTexture a, RenderTexture b) => Debug.Log($"{Time.frameCount}: {nameof(OnRenderImage)}");
void OnBeforeRender() => Debug.Log($"{Time.frameCount}: {nameof(OnBeforeRender)}");
void OnARCameraFrameReceived(ARCameraFrameEventArgs _) => Debug.Log($"{Time.frameCount}: {nameof(OnARCameraFrameReceived)}");
}
On what platform? On Android, I consistently get this ordering (which is what I would expect):
OnARCameraFrameReceived Update OnBeforeRender OnRenderImage
In the Editor, I get the same ordering of
OnBeforeRender
andOnRenderImage
.This is my test script:
using UnityEngine; using UnityEngine.XR.ARFoundation; [RequireComponent(typeof(Camera))] [RequireComponent(typeof(ARCameraManager))] public class EventOrdering : MonoBehaviour { void Start() { Application.onBeforeRender += OnBeforeRender; GetComponent<ARCameraManager>().frameReceived += OnARCameraFrameReceived; } void Update() => Debug.Log($"{Time.frameCount}: {nameof(Update)}"); void OnRenderImage(RenderTexture a, RenderTexture b) => Debug.Log($"{Time.frameCount}: {nameof(OnRenderImage)}"); void OnBeforeRender() => Debug.Log($"{Time.frameCount}: {nameof(OnBeforeRender)}"); void OnARCameraFrameReceived(ARCameraFrameEventArgs _) => Debug.Log($"{Time.frameCount}: {nameof(OnARCameraFrameReceived)}"); }
I test in editor.order was uncorrect. On ios build,order was correct.
I want to get camera render position and ar position. Theoretically these two values are equal.
But I don't know why OnRenderImage() was called before onBeforeRender() in same frame count. Here is call order by frameCount:
OnRenderImage():197 OnBeforeRender():197 OnCameraFrameReceived():198 OnRenderImage():198
OnRenderImage():209 OnBeforeRender():209 OnCameraFrameReceived():210 OnRenderImage():210