I am using a SceneCapture2d in c++ to render to a texture and noticed it is a frame behind since it captures the scene at the end of the frame and uses that texture at the beginning of the following frame. Is there a way to force the capture to happen at the beginning of the frame so it isn’t a frame behind when rendering? Is there a better way to avoid creating a texture and instead render to stencil buffer? Thanks.
If you are using the ‘update every frame’ method, it will happen on the next frame, there’s nothing you can do about that. Look at USceneCaptureComponent::CaptureSceneDeferred() to see why.
The only way to correct this would be to turn the ‘update every frame’ feature off and implement your own version of the capture each frame.
There are some caveats with doing that, though. You will need to pay attention to the ‘Tickgroup’ of the scene component. If you are trying to capture a scene with any physics you will need to make sure that that stuff has all been completed before you attempt a capture. Otherwise you can cause crashes or hangs. By default, the scene capture component belongs in the ‘TG_DuringPhysics’ tick group, which works fine enough with deferred updates, but can cause loads of trouble if you’re trying to manually update the capture on a component that is also in the middle of a physics update.