0
$\begingroup$

Please take a look at this video:

description

My objective was to have the text follow the camera such that it would be stationary throughout the camera movement and able to convey information about the current frame.

However, even after linking the text object to the camera by setting the camera as a parent of the text, the text doesn't follow the camera correctly when rendering to an animation, instead jittering like in the gif. Everything works fine when rendering the frames individually and when displaying in the viewport. Any ideas as to what might be causing this, and generally why rendering an animation isn't the same as consecutively rendering the frames of that animation?

Thanks for your time from a new user :)

EDIT: After having another look at the problem, its linked to the script I use to update the body of the text each frame:

import bpy

def update(self):
    text = bpy.data.objects['Annotation']
    frame = bpy.context.scene.frame_current
    text.data.body = text["frame_data"][str(frame)]
    
    
def register():
    bpy.app.handlers.frame_change_post.append(update)

def unregister():
    bpy.app.handlers.frame_change_post.remove(update)

register()

The jittering starts only after the script has been registered

$\endgroup$
1
  • $\begingroup$ could you provide more information about how it is parented, its modifiers? eventually, share you blend file here blend-exchange.com $\endgroup$
    – lemon
    Commented Apr 8, 2023 at 8:01

1 Answer 1

0
$\begingroup$

The documentation:

bpy.app.handlers.frame_change_post

Called after frame change for playback and rendering, after the data has been evaluated for the new frame.

So the data as already been evaluated for the next frame that will be rendered.

If you want the modification to be taken into account correctly, change it to frame_change_pre.

bpy.app.handlers.frame_change_pre

Called after frame change for playback and rendering, before any data is evaluated for the new frame. This makes it possible to change data and relations (for example swap an object to another mesh) for the new frame. Note that this handler is not to be used as ‘before the frame changes’ event. The dependency graph is not available in this handler, as data and relations may have been altered and the dependency graph has not yet been updated for that.

The code should be:

def register():
    #bpy.app.handlers.frame_change_post.append(update)
    bpy.app.handlers.frame_change_pre.append(update)

def unregister():
    #bpy.app.handlers.frame_change_post.remove(update)
    bpy.app.handlers.frame_change_pre.remove(update)
$\endgroup$
2
  • $\begingroup$ Thank you! That completely fixed it ^^ I'm still a bit puzzled why consecutive individual renders != animation render and why doing the update post frame instead of pre frame should affect the position of the text at all, as it is just the body that is updated, but its probably best to just let that lie for now $\endgroup$ Commented Apr 11, 2023 at 9:22
  • $\begingroup$ the scene is correctly updated (consecutively to modifications) only if the dependency graph is itself calculated/updated. For "change_post", the documentation mentions that this depsgraph is already calculated for the next rendering, in consequence if you modify something this modification cannot be correctly taken into account correctly (change "post" is post dg update). Change pre (pre dg update), still accepts modification as the dg will be updated after the modification and before the rendering. $\endgroup$
    – lemon
    Commented Apr 11, 2023 at 9:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .