Note that using the built-in duplicate or copy/paste mechanisms in Unity on the asset will not work properly
But after using HDAs in our workflow for several months, I’ve come to the conclusion that this limitation is absolutely crippling our use of Houdini, to the point of making it useless. Yes, I know there’s a ‘Duplicate Asset’ button, but that doesn’t actually solve the workflow issues.
The problem:
Pasting a HDA instance breaks *both* instances - the original and the new copy. Parameters may or may not work depending on instance, the curves editor is highly confused, cooking often updates the wrong asset.
Saving and reopening a scene after a HDA has been pasted causes different breakage behaviour. This makes it difficult to establish which/where HDAs have broken.
Breakage occurs silently. That means a HDA can be accidentally pasted by one designer and checked in, only for another designer to find that the HDAs are broken and not know why.
The ‘duplicate asset’ button goes against the normal Unity workflow. Designers are (quite reasonably) expecting copy&paste to work.
It’s really easy to accidentally copy&paste a HDA without realising it, especially HDAs are nested inside other objects or multiple people working on a scene. It’s not reasonable for users to manually inspect *every* object within a hierarchy before pressing ctrl-c / ctrl-v.
Once a HDA instance is broken, there doesn’t seem to be a way to fix it other than deleting it and starting again. Which means re-adding it and tediously re-creating all the parameters(see 7) and curves (see 8).
Recreating parameters is highly error prone, since unlike normal components they can’t be copy and pasted across to the new instance, but must be manually adjusted one by one.
Recreating curves is even worse, since there’s no raw values exposed, so they have to be redrawn from scratch. Which makes it basically impossible to duplicate the exact same curve.
This basically makes HDAs unusable within Unity - our workaround workflow is to bring each HDA into it’s own scene, set the parameters and bake it into a prefab. Then use the non-HDA prefab everywhere. This is:
Slow and error prone
Creates a lot of file system noise - it adds a lot of asset files to the project that wouldn’t normally exist and have to be uniquely named and managed
Doesn’t really support unique per-instance HDAs
Makes editing the HDA instances tedious rather than just adjusting the parameters in-place.
While this works, at this point we might as well just be exporting static fbx files from Houdini. Which defeats the whole point of using Houdini and HDAs in the first place.
Possible Solutions
Ok, so Unity doesn’t provide explicit copy/paste/duplicate events. That sucks, but this is too important so let’s have a look at how to fix it.
ValidateCommand
https://docs.unity3d.com/ScriptReference/EventType.ValidateCommand.html [docs.unity3d.com]
Allegedly sends paste/duplicate events, but after hacking around with it for a little while, I couldn’t get this to actually send events for a HDA instance.
Monitoring InstanceId
Getting HoudiniAssetRoot to monitor it’s instanceId and see when it’s changed reliably catches copy/paste/duplicate events:
[SerializeField] private int cachedInstanceId = 0; private void Awake() { // Note these need the component to be tagged as [ExecuteInEditMode] if (this.cachedInstanceId == 0) { // No cached instance id set. Either: // This component is just being created from scratch (which might be via HEU_HoudiniAsset::Duplicate) // Or this is an old component (before cachedInstanceId was added) being loaded from disk Debug.Log("Fresh asset root Awake for " + this.gameObject.name); } else if (this.cachedInstanceId != this.GetInstanceID()) { // Instance id has changed. Either: // This object is the output of a paste/duplicate command // We're an existing component with a valid cached id which is being reloaded from disk (eg. scene opening) Debug.Log("Awake - instance id changed for " + this.gameObject.name); } this.cachedInstanceId = this.GetInstanceID(); }
So now we just need to figure out which state needs to be reinitialised for the clone.
It looks like the assetId, asset cache folder path and the ‘b force update’ don’t update correctly, but I’m not sure on how to refresh these internally.
Sorry for the wall of text, it’s been driving our designers crazy and this is the first I’ve been able to sit down and work through it. Any help fixing it (or getting it fixed in the plugin) as a matter of urgency would be really appreciated.
Platform: Windows 10
Houdini version: 18.0.348
Houdini engine: 3.3.2
HOUDINI_PLUGIN_VERSION = 2