Porting my addons to 2.8 - missing scene_update_post handler

Two of my addons (VSE Quick Functions, and another I have not released yet) rely on the scene_update_post handler, which has been removed along with scene_update_pre
(See the first ‘Open Topic’ at: https://developer.blender.org/T47811 ).

I don’t think this functionality can be properly replicated with a modal operator. I have tried in the past and run into reliability issues, and as far as I know, this isn’t what modal operators are supposed to be used for either. So what am I supposed to use for this now?

I get that it isn’t working the way it was intended right now, but without an effective alternative, removing it entirely is not the solution…

5 Likes

I like to know this too.

Same issue here. Having a way to continously run code is crucial for some addons. If used properly, the overhead it adds to viewport is minor but the benefit is great. So removing it without alternative is a bad choice, please bring it back.

1 Like

the weekly notes of jun 26 2018 mentioned the following

Handler bpy.app.handlers.scene_update_pre
===========================================

This was being mis-used because of a bug causing it to run constantly.

API's to replace this can be:

- A timer API to run Python code at less frequent intervals,
  encourage timers to run less frequently,
  the timer must be explicitly told to run again each time
  (avoiding timers being left enabled)

  - Bastien handles.

- Another use case use synchronizing data
  a depsgraph API needs to handle this.

  - Sergey handles.

So it’s unlikely this handler is going to be back, @mont29 might be able to comment on how far out the replacement api is.

So this is unclear. is scene_update_post handler still possible with 2.8? Or just the scene_update_pre going away?

Both pre and post are gone.

Any replacement planned? The ability to run code on scene updates and repeteadly is a very much needed feature for some addons.

There will be a replacement, it’s not clear yet what form it will take.

2 Likes

For me and other this means our addons will not work with 2.8 - I made 2 years of work in add-ons and sold on Blendermarket, donate to Blender and users where very happy. Now start from scratch again? I cannot do. Like I ask you “start Blender from scratch again cause we made changes to C and remove 50% of what Blender use”.

1 Like

There is no need to start from scratch. There will be a replacement for this function.

There is now a depsgraph_update_pre and depsgraph_update_post, which runs when something actually changed in the scene, not continuously.

For the remaining uses cases, something is being worked on here:
https://developer.blender.org/D3977

3 Likes

Thank you so much for letting us know! That should do the job for my addon. And it is also very nice that I will not have to check manually if the scene was updated anymore to stop it from firing the code continuously.

Fantastic! Sounds like its actually doing what the removed handlers were supposed to be doing in the first place.
Only question tho, why not just keep the original names?
Regardless, thank you so much for devoting the time to this! I, and many other addon devs appreciate it greatly!

Can this function be used for monitoring size changes in the Sequencer Preview area and call “Fit Preview In Window” if changed, without weighing down the system?

It would be great to have this as an checkbox option in the Sequencer/Preview/View menu in the VSE - Reworked project. If it is possible, here’s a link if someone here wants to help out with this: https://github.com/samytichadou/blender_vse_reworked

There are some cases in which the depsgraph_update_pre/post handlers can’t be used (did not test your case).
If it does not work, you can still fallback to the new Timer API.

Can anyone help me, how replace
bpy.app.handlers.scene_update_post.append
with
depsgraph_update_pre/post

From link it look like it still under construction and not sure how to implement. I need update always when user input like mouse move or keyboard input.

There is no handler function that runs on every input, generally this is bad for performance and should be avoided. In 2.7 scene_update_post would run continuously no matter if anything happened, so if you want the same thing in 2.8 you can use the timer API with a very small interval.

Looks like there are some limitations in the timer API, for example there is no context available in the callback functions (see https://developer.blender.org/T62051).

So this doesn’t seem to be a valid replacement for scene_update_* after all…

I never see performance problem with my addon and 2.79 - I checked carefully cause my app need run fast. Trying timer api but got lots of other issues right now so I maybe come back to this later.

Bug report of 2015: https://developer.blender.org/T45173
I don’t agree it is broken by design. I really want my event to only be called when the scene changes. (Or only when a specific object changes.)
Now scene_update_post is difficult to debug, as print statements in my callback function will litter the console.
Is there an alternative to this function?