Search Issue Tracker
By Design
Votes
0
Found in
2021.3.37f1
2022.3.26f1
2023.2.20f1
6000.0.0f1
Issue ID
UUM-70468
Regression
No
Camera.current returns null when Camera.targetTexture is set to null in OnPostRender
How to reproduce:
1. Open the “CamCurrent“ project
2. Open the “Assets/main.unity” scene
3. Enter Play Mode
4. In the Game view enable “Use Camera.Render()”
5. Observe the “Camera.current” text
Expected result: The text is “Camera.current=Main Camera (UnityEngine.Camera)”
Actual result: The text is “Camera.current=”
Reproduced with: 2021.3.37f1, 2022.3.26f1, 2023.2.20f1, 6000.0.0f1
Reproduced on: Windows 10 (by reporter), Windows 11
Not reproduced on: No other environment tested
Notes:
1. Reproducible in the Player
2. If another camera is enabled, like the “UICamera” from the “main” scene, then the text will report a non-null value but this is still incorrect
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [Render Graph Viewer] Resource list icons cropped and in inconsistent positions
- Scene View with Debug Draw Mode enabled is gray when GPU Resident Drawer is enabled
- The UI is not visible when resizing out of focus built Player window with Application.runInBackground set to false
- [Linux] "Error while reading movie" errors are thrown when opening templates
- Shader warnings are being thrown after building Mixed Reality Template
Resolution Note:
The script provided in the attached project doesn't seem to be using the API correctly. Calling Render() directly is intended to be used on disabled cameras, as explained in the documentation: https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Camera.Render.html
It is not totally clear what the exact use case here is, but if the intent is to manually control the timing when the camera rendering happens. please try something like this instead:
1. Set your Main Camera to target back buffer (targetTexture = null), but render no objects (Occlusion Culling = Nothing).
2. Create a second GameObject with Camera component, calling this the OffScreen Camera. Configure it to render to a render texture. This will contain the rendering result. This Camera component should be disabled, and you can call camera.Render() e.g. from the Update function.
3. Create a script that uses the OnRenderImage event function to blit the OffScreen Camera's renderTexture to the destination RenderTexture provided in the event function, using Graphics.Blit. Attach this script to the Main Camera GameObject. See https://docs.unity3d.com/6000.0/Documentation/ScriptReference/MonoBehaviour.OnRenderImage.html for details.
The above recommendation is for built-in render pipeline. If you are using a Scriptable Render Pipeline instead, please refer to https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@17.0/manual/User-Render-Requests.html.