Notifications
Clear all

[Closed] Best way to execute a script once per frame?

I need to execute a script ONCE on every frame as part of a rig. I’ve tried hiding it on a list controller on the position of one of the objects but this seems to execute the script twice per frame. Possibly cause of dependencies? This would be workable but not ideal (cause of the extra overhead) but even worse than extra overhead, the second time it executes it returns different values from the first time. This is the most baffling thing of all. The values in question are distance calculations.

If I just run the script from the script editor rather than from a script controller, it acts as I would expect.

Because of the way we handle assets, I can’t install the script in the scene, it needs to be on an object that’s part of the asset somehow so that when assets move from scene to scene, the script goes with it. I can’t post the full script or the scene, but I’ll try to make a cutdown of the scene and script controller to demonstrate the problem a bit later on if no one has a quick answer for me.

Cheers,
Cg.

10 Replies

OK, I’ve sorted out the multiple execution/weird value issue. Seems like a dependency bug related to path constraints. Not going to worry about that right now. I’ll just work around it and move the script elsewhere.

But I am still keen to find the best way that people execute scripts as part of rigs. In hindsight, I was probably a bit simplistic in my wording of “executed every frame” cause they also need to work as animators are doing their thing or as part of any usual updates like when pointcaches are being recorded etc. I’m really hoping to avoid scene callbacks ’cause I need the script to be bundled with the asset.

Cheers,
Cg.

This is something I asked before if I remember. It would be great sometimes to do that: some kind of global function that is called once a frame…

48Design: You can install a function within a custom attribute on the rootnode of the scene and install a callback to execute it. But that setup lives in the scene, rather than part of a physical “asset” that can be moved from scene to scene easily.

Script controllers run as time changes

PePeTD: They generally do. But not all of them. Hidden objects don’t necessarily have their script controllers evaluated. They need to be part of something that needs it to be updated. But the issue I have is that everything that is being updated as part of this rig causes dependency loop issues or illegal self references in the script controllers.

Cheers,
Cg.

 lo1

Read about timeChangeCallback

Lo: How do you go about attaching callbacks to a rig? I only know how to add a callback to a scene rather than to objects.

Cg.

How do you go about attaching callbacks to a rig?

can be installed on custom attribute on post load event or a scripted object/helper doing the same thing possibly.

Thanks Klvnk. Could you elaborate a little more? Your suggestion sounds promising. I know how to add scripted custom attributes with functions/parameters etc. to things like objects, modifiers or the rootnode of a scene. Can you put a callback on an object using custom attributes?

I’m mostly not sure what you meant by:

can be installed on custom attribute on post load event

Cheers,
Cg.

Page 1 / 2