Skip to content

Commit 01fce94

Browse files
committed
Fixed an issue where rebuilding an HDA in Unity would pick up the wrong input object if it has the same name.
1 parent 9e7dd66 commit 01fce94

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_AssetPreset.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public class HEU_InputObjectPreset
118118
public string _gameObjectName;
119119
public bool _isSceneObject;
120120

121+
// When rebuilding an HDA we need to store the gameObject, but not serialize it for presets.
122+
[System.NonSerialized] public GameObject _gameObject;
123+
121124
public bool _useTransformOffset = false;
122125

123126
public Vector3 _translateOffset = Vector3.zero;
@@ -203,7 +206,7 @@ public static class HEU_AssetPresetUtility
203206
public static void SaveAssetPresetToFile(HEU_HoudiniAsset asset, string filePath)
204207
{
205208
// This should return an object filled with preset data, and which we can serialize directly
206-
HEU_AssetPreset assetPreset = asset.GetAssetPreset();
209+
HEU_AssetPreset assetPreset = asset.GetAssetPreset(true);
207210

208211
if (assetPreset != null)
209212
{

Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_HoudiniAsset.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ public void ResetMaterialOverrides()
16421642
}
16431643

16441644
/// <inheritdoc />
1645-
public HEU_AssetPreset GetAssetPreset()
1645+
public HEU_AssetPreset GetAssetPreset(bool sceneRelativeGameObjects)
16461646
{
16471647
if (string.IsNullOrEmpty(_assetName))
16481648
{
@@ -1684,7 +1684,7 @@ public HEU_AssetPreset GetAssetPreset()
16841684
if (inputNode != null)
16851685
{
16861686
HEU_InputPreset inputPreset = new HEU_InputPreset();
1687-
inputNode.PopulateInputPreset(inputPreset);
1687+
inputNode.PopulateInputPreset(inputPreset, sceneRelativeGameObjects);
16881688
assetPreset.inputPresets.Add(inputPreset);
16891689
}
16901690
}
@@ -2191,7 +2191,7 @@ private bool StartRebuild(bool bPromptForSubasset, int desiredSubassetIndex)
21912191
}
21922192

21932193
// Save parameter preset
2194-
_savedAssetPreset = GetAssetPreset();
2194+
_savedAssetPreset = GetAssetPreset(false);
21952195

21962196
if (_assetID != HEU_Defines.HEU_INVALID_NODE_ID && !IsAssetValidInHoudini(session))
21972197
{

Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_InputNode.cs

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ public void LoadPreset(HEU_InputPreset inputPreset)
642642
}
643643

644644
/// <inheritdoc />
645-
public void PopulateInputPreset(HEU_InputPreset inputPreset)
645+
public void PopulateInputPreset(HEU_InputPreset inputPreset, bool sceneRelativeGameObjects)
646646
{
647647
inputPreset._inputObjectType = _inputObjectType;
648648

@@ -661,15 +661,27 @@ public void PopulateInputPreset(HEU_InputPreset inputPreset)
661661

662662
if (inputObject._gameObject != null)
663663
{
664-
inputObjectPreset._gameObjectName = inputObject._gameObject.name;
665-
666-
// Tag whether scene or project input object
667664
inputObjectPreset._isSceneObject = !HEU_GeneralUtility.IsGameObjectInProject(inputObject._gameObject);
668665
if (!inputObjectPreset._isSceneObject)
669666
{
670667
// For inputs in project, use the project path as name
671668
inputObjectPreset._gameObjectName = HEU_AssetDatabase.GetAssetOrScenePath(inputObject._gameObject);
672669
}
670+
else
671+
{
672+
if (sceneRelativeGameObjects)
673+
{
674+
// If scene relative (used for presets) store the name of the object so it works in any scene.
675+
inputObjectPreset._gameObjectName = inputObject._gameObject.name;
676+
inputObjectPreset._gameObject = null;
677+
}
678+
else
679+
{
680+
// If not scene relative, store the game object. This is used for rebuilding.
681+
inputObjectPreset._gameObjectName = "";
682+
inputObjectPreset._gameObject = inputObject._gameObject;
683+
}
684+
}
673685
}
674686
else
675687
{
@@ -1369,9 +1381,12 @@ internal void LoadPreset(HEU_SessionBase session, HEU_InputPreset inputPreset)
13691381
{
13701382
bSet = false;
13711383

1384+
// Fetch the gameObject. This will with be the name of an object in the scene, _gameObjectName,
1385+
// used for presets, or an explicit gameObject, _gameObject, used during rebuilds.
1386+
1387+
GameObject inputGO = null;
13721388
if (!string.IsNullOrEmpty(inputPreset._inputObjectPresets[i]._gameObjectName))
13731389
{
1374-
GameObject inputGO = null;
13751390
if (inputPreset._inputObjectPresets[i]._isSceneObject)
13761391
{
13771392
inputGO = HEU_GeneralUtility.GetGameObjectByNameInScene(inputPreset._inputObjectPresets[i]._gameObjectName);
@@ -1387,22 +1402,25 @@ internal void LoadPreset(HEU_SessionBase session, HEU_InputPreset inputPreset)
13871402
HEU_Logger.LogErrorFormat("Unable to find input at {0}", inputPreset._inputObjectPresets[i]._gameObjectName);
13881403
}
13891404
}
1405+
}
1406+
else if (inputPreset._inputObjectPresets[i]._gameObject != null)
1407+
{
1408+
inputGO = inputPreset._inputObjectPresets[i]._gameObject;
1409+
}
13901410

1391-
if (inputGO != null)
1392-
{
1393-
HEU_InputObjectInfo inputObject = InternalAddInputObjectAtEnd(inputGO);
1394-
bSet = true;
1395-
1396-
inputObject._useTransformOffset = inputPreset._inputObjectPresets[i]._useTransformOffset;
1397-
inputObject._translateOffset = inputPreset._inputObjectPresets[i]._translateOffset;
1398-
inputObject._rotateOffset = inputPreset._inputObjectPresets[i]._rotateOffset;
1399-
inputObject._scaleOffset = inputPreset._inputObjectPresets[i]._scaleOffset;
1400-
}
1401-
else
1402-
{
1403-
HEU_Logger.LogWarningFormat("Gameobject with name {0} not found. Unable to set input object.",
1404-
inputPreset._inputAssetName);
1405-
}
1411+
if (inputGO != null)
1412+
{
1413+
HEU_InputObjectInfo inputObject = InternalAddInputObjectAtEnd(inputGO);
1414+
bSet = true;
1415+
inputObject._useTransformOffset = inputPreset._inputObjectPresets[i]._useTransformOffset;
1416+
inputObject._translateOffset = inputPreset._inputObjectPresets[i]._translateOffset;
1417+
inputObject._rotateOffset = inputPreset._inputObjectPresets[i]._rotateOffset;
1418+
inputObject._scaleOffset = inputPreset._inputObjectPresets[i]._scaleOffset;
1419+
}
1420+
else
1421+
{
1422+
HEU_Logger.LogWarningFormat("Gameobject with name {0} not found. Unable to set input object.",
1423+
inputPreset._inputAssetName);
14061424
}
14071425

14081426
if (!bSet)

Plugins/HoudiniEngineUnity/Scripts/PublicWrappers/IHEU_HoudiniAsset.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ public interface IHEU_HoudiniAsset
489489
/// and their presets.
490490
/// </summary>
491491
/// <returns>A new HEU_AssetPreset populated with parameter preset and curve presets</returns>
492-
HEU_AssetPreset GetAssetPreset();
492+
HEU_AssetPreset GetAssetPreset(bool sceneRelativeObjects);
493493

494494
/// <summary>
495495
/// Gets or creates a PDG asset link for this asset, if it doesn't exist.

Plugins/HoudiniEngineUnity/Scripts/PublicWrappers/IHEU_InputNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,6 @@ public interface IHEU_InputNode
251251
/// Populates the specified inputPreset with this HEU_InputNode's data
252252
/// </summary>
253253
/// <param name="inputPreset">The input preset</param>
254-
void PopulateInputPreset(HEU_InputPreset inputPreset);
254+
void PopulateInputPreset(HEU_InputPreset inputPreset, bool sceneRelativeGameObjects);
255255
}
256256
} // HoudiniEngineUnity

0 commit comments

Comments
 (0)