diff --git a/source/MaterialXCore/Definition.cpp b/source/MaterialXCore/Definition.cpp index 6b45baf195..cf89f93de6 100644 --- a/source/MaterialXCore/Definition.cpp +++ b/source/MaterialXCore/Definition.cpp @@ -185,16 +185,26 @@ StringVec TargetDef::getMatchingTargets() const vector UnitTypeDef::getUnitDefs() const { - const auto datalibrary = getDocument()->hasDataLibrary() ? getDocument()->getRegisteredDataLibrary() : getDocument(); - vector unitDefs; - for (UnitDefPtr unitDef : datalibrary->getChildrenOfType()) + for (UnitDefPtr unitDef : getDocument()->getChildrenOfType()) { if (unitDef->getUnitType() == _name) { unitDefs.push_back(unitDef); } } + // Gather unitdefs from Data library + if (getDocument()->hasDataLibrary()) + { + for (UnitDefPtr unitDef : getDocument()->getRegisteredDataLibrary()->getChildrenOfType()) + { + if (unitDef->getUnitType() == _name) + { + unitDefs.push_back(unitDef); + } + } + + } return unitDefs; } diff --git a/source/MaterialXCore/Document.h b/source/MaterialXCore/Document.h index 6fc9523cca..6c0fbb6149 100644 --- a/source/MaterialXCore/Document.h +++ b/source/MaterialXCore/Document.h @@ -554,7 +554,7 @@ class MX_CORE_API Document : public GraphElement /// Return a vector of all Member elements in the TypeDef. vector getUnitDefs() const { - return getChildrenOfType(); + return hasDataLibrary() ? getChildrenOfType(getRegisteredDataLibrary()) : getChildrenOfType(); } /// Remove the UnitDef, if any, with the given name. @@ -585,7 +585,7 @@ class MX_CORE_API Document : public GraphElement /// Return a vector of all UnitTypeDef elements in the document. vector getUnitTypeDefs() const { - return getChildrenOfType(); + return hasDataLibrary() ? getChildrenOfType(getRegisteredDataLibrary()) : getChildrenOfType(); } /// Remove the UnitTypeDef, if any, with the given name.