UPBGE / upbge

UPBGE, the best integrated game engine in Blender
https://upbge.org
Other
1.43k stars 180 forks source link

Fix 1 frame delay when copying transformations using python #1887

Closed opheroth closed 4 months ago

opheroth commented 5 months ago

Fix 1 frame delay when copying transformations from one object to another using python in game engine.

youle31 commented 5 months ago

Hello,

I wouldn't change the pipeline order for this, it sounds too risky... Scripts can also need to be executed before UpdateAnimations (a script calling playAction for example).

Instead of changing upbge source code, i'd suggest to execute the script in a KX_Scene pre_draw callback, and this should solve the issue.

I saw that Musikai shared a file on blenderforartists forum: sync_test.zip

This file can be adapted like this: sync_test2.zip

Parenthesis: I know that blender 2.79 behaved differently, but current way of working sounds ok to me, even if in this special case it needs to delay the script execution in a pre_draw callback.

opheroth commented 5 months ago

I've tried calling pre_draw callbacks for animated armatures, but it didn't work, I've tried copying bone location but for some reason, the delay is still there, that's why I moved that part, and that fixed it, I haven't found problems in my projects that uses animated armatures. Is there a way to fix that armature problem without editing source code?

opheroth commented 5 months ago

Hello,

I wouldn't change the pipeline order for this, it sounds too risky... Scripts can also need to be executed before UpdateAnimations (a script calling playAction for example).

Instead of changing upbge source code, i'd suggest to execute the script in a KX_Scene pre_draw callback, and this should solve the issue.

I saw that Musikai shared a file on blenderforartists forum: sync_test.zip

This file can be adapted like this: sync_test2.zip

Parenthesis: I know that blender 2.79 behaved differently, but current way of working sounds ok to me, even if in this special case it needs to delay the script execution in a pre_draw callback.

In this file, the problem is still there for the armature, the moving object is fine, but not the one copying the bone's tail position.

CopyPosArm.zip

youle31 commented 5 months ago

There are other reasons imo why UpdateAnimations is in RenderCamera -> because it needs to wait that camera matrices (view and projection) are set.

About your file, it sounds to work like that:

CopyPosArm2.zip

opheroth commented 4 months ago

Thanks for the help, and the explanation. It was very useful.