# Sun object not moving when Rendering Animation

I've problem Rendering sun rotation animation. Steps to reproduce:

1. Create the sun object
2. Set 1st keyframe
• Select keyframe
• Rotate sun object using the handle
• "I" > Select Rotation
3. Set 10th keyframe (Reproduce same steps found in 2nd point)
4. Add frame_change_post handler to print sun rotation_euler
5. Run Render > Render Animation

The result was 11 times (0-10) printed same rotation Euler <Euler (x=-7.9113, y=0.2392, z=-7.1615), order='XYZ'> .But when I move from keyframe to keyframe Euler XYZ positions are updated. Why is that so?

Here is a demo plugin created to replicate the issue:

bl_info = {
"name": "Sun animation using lever",
"author": "karlisup",
"version": (1, 0),
"blender": (2, 80, 0),
}
import bpy
from bpy.app.handlers import persistent

@persistent
def sun_handler(scene, depsgraph):
if "Sun" not in bpy.data.objects:
create_sun()
sun = bpy.data.objects["Sun"]
print(scene.frame_current, sun.rotation_euler)

def create_sun():
bpy.context.view_layer.active_layer_collection = bpy.context.view_layer.layer_collection
light_data = bpy.data.lights.new(name="Sun", type='SUN')
light_data.energy = 30
light_object = bpy.data.objects.new(name="Sun", object_data=light_data)
light_object.location = (5, 5, 5)
bpy.context.view_layer.objects.active = light_object

def register():
bpy.app.handlers.frame_change_post.append(sun_handler)

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

if __name__ == "__main__":
register()

• To me, this script is working correctly except that the handler should have 2 arguments: the scene and the depsgraph. To tell it another way, I don't think what is printed is from the function indicated in the question. – lemon Feb 23 '20 at 8:42
• Seen your edit. What I meant was not only about the missing arguments but the hypothesis that all works fine (it works fine when I test it) but these missing arguments or something else make so what is printed is your env is not the rotation of the expected object. – lemon Feb 24 '20 at 11:13
• Thanks, @lemon for the comment. I updated the code regarding handler parameters. I'll try to clarify my question as this doesn't quite solve my confusion. The problem is with 2 views. In one Euler changes sun rotation coordinates, but whenever Animation is Rendered - it doesn't. I tried to illustrate it here: youtu.be/0Q8FsuDrC1k I – karlisup Feb 24 '20 at 11:40
• You say that I should be somehow extracting rotation of an object from the scene (the context)? Sorry, Blender is new to me :) – karlisup Feb 24 '20 at 11:42
• "what is printed is your env is not the rotation of the expected object" This totally makes sense. Could you help me to understand how to get a rotation of the object while I am using "Render Animation" as I couldn't find examples in existing atmosphere plugins? – karlisup Feb 24 '20 at 11:50

It seems that during rendering you need to use the depsgraph so that you obtain an evaluated object.

Don't know why this is not useful when just playing the animation.

sun = sun.evaluated_get(depsgraph)


In the complete function:

@persistent
def sun_handler(scene, depsgraph):
if "Sun" not in bpy.data.objects:
create_sun()
sun = bpy.data.objects["Sun"]
sun = sun.evaluated_get(depsgraph)
print(scene.frame_current, sun.rotation_euler)


A link to the documentation if needed.