hello,
i'm trying the new plugin (v2 beta), and i want to duplicate many copy of my asset (a building for a little town)and change for each copy some parameters.
so i want to do it by C#. but i can't find a way to do it.
(i've done it before with the plugin V1 but all is so different…)
is it possible to have a (very)simple example of creating (or duplicating) an asset by C# ?
thank's a lot.
phil
create or duplicate asset by C#
2218 2 2- chabis
- Member
- 9 posts
- Joined: 11月 2016
- Offline
- seelan
- Member
- 571 posts
- Joined: 5月 2017
- Offline
Very simple actually. Just call HEU_HoudiniAsset:: DuplicateAsset() which should return a new GameObject that is a duplicate of the asset. This is what the Duplicate Asset button does.
Here is an example of duplicating a selected asset via C#:
Note that I just fixed a regression with the DuplicateAsset function that will be in tomorrow's build (H16.5.502). The duplicated asset wasn't cooking.
The reasons for the explicit duplicate method as opposed to using Unity's built-in duplicate or copy/paste mechanism are that aside from the lack of a consistent way to capture copy/paste or duplicate events in the Unity, we also need to create a duplicate asset in the background Houdini session that connects to the Unity's duplicate instance, and we're using ScriptableObjects internally in the asset, which do not get duplicated via the built-in way but rather just have their references copied.
Here is an example of duplicating a selected asset via C#:
[MenuItem("Test/TestDuplicate")] public static void TestDuplicate() { GameObject rootGO = Selection.activeGameObject; if(rootGO == null) { Debug.LogWarning("Nothing selected. You need to select an asset!"); return; } // The selected gameobject is the asset's root gameobject. // Get the root component (HEU_HoudiniAssetRoot) which will allow us to get the asset component (HEU_HoudiniAsset) itself. HoudiniEngineUnity.HEU_HoudiniAssetRoot root = rootGO.GetComponent<HoudiniEngineUnity.HEU_HoudiniAssetRoot>(); if (root != null) { HoudiniEngineUnity.HEU_HoudiniAsset asset = root._houdiniAsset; // This will return a duplicated asset as a gameobject asset.DuplicateAsset(); } }
Note that I just fixed a regression with the DuplicateAsset function that will be in tomorrow's build (H16.5.502). The duplicated asset wasn't cooking.
The reasons for the explicit duplicate method as opposed to using Unity's built-in duplicate or copy/paste mechanism are that aside from the lack of a consistent way to capture copy/paste or duplicate events in the Unity, we also need to create a duplicate asset in the background Houdini session that connects to the Unity's duplicate instance, and we're using ScriptableObjects internally in the asset, which do not get duplicated via the built-in way but rather just have their references copied.
Edited by seelan - 2018年6月12日 09:45:40
- chabis
- Member
- 9 posts
- Joined: 11月 2016
- Offline
-
- Quick Links