Python Handle - init vs onActivate concepts

   507   3   0
User Avatar
Member
165 posts
Joined: Aug. 2013
Online
Can someone please help me understand conceptually the difference between these two? Why or when should you make use of one or the other?
User Avatar
Staff
453 posts
Joined: Feb. 2018
Offline
__init__() is the Python handle constructor and is called when the state is entered and the handle is created.
onActivate() is called by Houdini to initialize an existing handle, either when the state is first entered or when it is resumed.

When the state exits, onDeactivate() is called and the handle is deleted. The next time the state is entered, a new handle is created and onActivate() is called again.

Interrupting a state does not delete the handle, but still triggers onDeactivate().
User Avatar
Member
165 posts
Joined: Aug. 2013
Online
mabelzile
__init__() is the Python handle constructor and is called when the state is entered and the handle is created.
onActivate() is called by Houdini to initialize an existing handle, either when the state is first entered or when it is resumed.

When the state exits, onDeactivate() is called and the handle is deleted. The next time the state is entered, a new handle is created and onActivate() is called again.

Interrupting a state does not delete the handle, but still triggers onDeactivate().

Great, things are starting to make sense.
Can you share a bit of insight on how to use onDeactivate specifically? Do you need to call something to delete the handle or is that handled by Houdini on exiting the viewer state? I know about registering, is that the same?
User Avatar
Staff
453 posts
Joined: Feb. 2018
Offline
Houdini deletes handles automatically when the state exits, so this is handled for you. `onDeactivate()` can be used if you need to perform additional cleanup or manage handle settings, etc.
I
  • Quick Links