How to clear userDataDict on HDA save

   1933   5   2
User Avatar
Member
78 posts
Joined: May 2018
Offline
My studio uses the hou.node.userDataDict to save a lot of pipeline-specific data to the nodes in the scene. Unfortunately, we've recently discovered that this data is saved along with the HDA whenever we update an HDA's definition, resulting in unexpected bugs with our pipeline tools.

While we are currently working around this by having devs clean out extra cached data before publishing an HDA, it often results in user error and headaches. Is there a way that we could automate the cleanup of the HDA's userDataDict whenever its definition is updated?
Edited by Ashen - Feb. 13, 2023 14:11:41
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
Yeah... I still consider this a bug since node state should absolutely not be a part of the definition. I filed #84279 many years ago for this issue (or some way to disable it from happening) so you could maybe have Support add your facility to the list of interested parties but I doubt things will ever be changed.

Your best bet is to use the stuff described here https://www.sidefx.com/docs/houdini/hom/hou/hdaEventType.html [www.sidefx.com] to do some sort of automated clearing/restoration of the data on all the instances of the node type you're updating in order to prevent the data from being stored when saved.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
78 posts
Joined: May 2018
Offline
I just found those callbacks and that seems like a promising start.

However, I'm not sure how to actually modify the HDADefinition to remove the cached values, as I don't see an obvious method in the API for accessing that data. Perhaps there is a way to modify the node and then overwrite the HDADefinition with the cleaned node before the definition is saved?
Edited by Ashen - Feb. 13, 2023 15:05:43
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
So when you save the asset Houdini will snapshot the userDataDict for the node instance that it is being saved from and shove it into the definition's CreateScript blob.

Unfortunately the callbacks only seem to provide the hou.HDADefinition and not the instance of the node being used to update it so in this case your callbacks will need to:
  • (BeforeAssetSaved) Use the definition to get the node type, then use that node type to get all the hou.Node instances of the type
  • (BeforeAssetSaved) Stash userDataDict() data on those nodes somewhere and clear the data so the nodes are clean
  • (AssetSaved) Restore the stashed data after the save with the clean node
Hopefully that makes sense.
Edited by graham - Feb. 13, 2023 15:14:55
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
78 posts
Joined: May 2018
Offline
That's a huge help. Thanks!
User Avatar
Member
78 posts
Joined: May 2018
Offline
Looks like the `BeforeAssetSaved` callback is Houdini 19.5 and up. I guess for earlier versions I can maybe just use the `AssetSaved` callback and then clean the node and trigger a new save of the HDA definition with the callback temporarily disabled.
  • Quick Links