Notifications
Clear all

[Closed] Time Change Callback delete?

hi guys,
i’m currently using Time Change Callback for controlling some controllers visibility depending on constraint weights.
i could use a when handler but i think it’s much less optimized.
the question is:
the callback function is in a custom attribute,
when i load a new file, does the function still exist?
That’s weird if it’s the case because it’s parent don’t exist anymore
Does anyone know something on that one

cheers

6 Replies

A Time callback does’nt get registered per its function name, but per the 3ds max internal “Value”.
If you reset Max or load a new file, that Value still exists internally and the timecallback still gets triggered, even if your local function has ceased to exist (current codeblock ends or you redefined it or threw it away… )
thus it’s sometimes hard to remove a timecallback when you do not have access to it via a variable any longer…
This is the reason why you can’t simply redefine a function, which is hooked into a timecallback. the timecallback will always trigger the first registered function, you explicitly have to unregister that function first

best way would be to define an empty global variable outside and before your rollout with the same name as your timecallback function will be. When maxscript creates the rollout and your function then, it see’s that there’s already a global variable of that name, and simply redefines the global to hold your function now…

the result of this is that that global still holds the function after your rollout block has ended, and you still can call “unregistertimecallback <global function name>” after that, in your case this should happen before you load a new file

hope i made clear what i mean ?

thanks spaceFrog that’s perfectly clear!
i made some ajustement to avoid the problem,
finally I just test a value in the callback function and unregister it, if value is undefined.
thanks again for the explanation!

The bad news is that unRegisterTimeCallback() not did it job all the time.
The same is true for unRegisterRedrawViewsCallback().

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

it’s not possible. any unregister…callback works absolutely right. i’ve never seen a problem.
only if i did something wrong.

(@spacefrog)
Joined: 11 months ago

Posts: 0

The unregister works. As i described, you just have to be sure that you keep a variable all the time holding the correct reference to the function . Max internally does not store the function name for those callbacks, but the internal maxscript “Value”.
Thus the usage of a global which is ALWAYS connected to the internal function “Value”, until you reassign it or Max is restarted…

Thanks to both for the coments but you think i need additional explanation on how this callbacks works?.. nor yet i do anything wrong! What i say is what i get – unreg-functions for both callbacks types – sometime works but not all the time. If you have 0 problems then what to say… you’re lucky (: