How to update the scene when exporting a RenderTarget from SceneCaptureComponent2D ?

Hi,

I’m trying to iteratively save images of a mesh from different viewpoints.

To do that, I have a mesh of the object, attached to this mesh I have a SrpingArm and attached to that spring arm I have a SceneCaptureComponent2D. I iteratively (in a For loop) rotate the spring arm to have a different viewpoint and then save the image that the SceneCaptureComponent2D is filming by using the UKismetRenderingLibrary::ExportRenderTarget function.
This works perfectly. However I am facing some issues when I want to iteratively add an SocketOffset to the SpringArm or change its TargetArmLength. What happen is that these parameters won’t change in the loop.
If I run the loop, wait for it to finish, and run another loop then the TargetArmLength and the Offset would have change between the two loops but not within the loops. Even stranger, when I manually call the function that apply those changes (rotate the SpringArm, add a SocketOffset and change the TargetArmLength) and save the image then everything works as expected, but when I call this function in a For loop it doesn’t. Which means that successively calling a function is somehow different from calling it in a For loop, and I don’t understand how nor why.

It seems that, within the For loop, the scene doesn’t get updated after the parameters changed. Which leads me to this question: **When using a SceneCaptureComponent2D, how to be sure that the scene is up-to-date before exporting its RenderTarget into a png image ? **

If you have any ideas what may go wrong, please feel free to tell, I’ve searching for a long time and I’m really running out of options right now. (ಥ﹏ಥ)

Thanks.

My guess is that because it is in a loop, the loop does all its iterations before the next tick, and the next tick is what updates the scene capture to render again. So because it is all in a loop happening before the next tick the next tick doesnt happen for each loop and the render target doesnt update until after the loop is done.

That is just a guess but you can try using a separate index variable and running this every Tick and increment that variale so it loops over seceral ticks instead of all at once to see if my theory is correct.

Thank you for your answer. It does make some sense, I will try that.

It worked! Thank you very much. ( ͡° ͜ʖ ͡°)

I’m glad to hear it :slight_smile: I wasnt sure but it seemed likely. please mark my answer as accepted and it will help others with this problem to find the solition faster