diff --git a/source/MaterialXCore/Definition.cpp b/source/MaterialXCore/Definition.cpp index 5ec7044325..3c2d068b1d 100644 --- a/source/MaterialXCore/Definition.cpp +++ b/source/MaterialXCore/Definition.cpp @@ -72,17 +72,28 @@ InterfaceElementPtr NodeDef::getImplementation(const string& target) const const TargetDefPtr targetDef = getDocument()->getTargetDef(target); const StringVec candidateTargets = targetDef ? targetDef->getMatchingTargets() : StringVec(); - // Search the candidate targets in order + // Search the candidate targets in inheritance order for (const string& candidateTarget : candidateTargets) { for (InterfaceElementPtr interface : interfaces) { - if (targetStringsMatch(interface->getTarget(), candidateTarget)) + const std::string& interfaceTarget = interface->getTarget(); + if (!interfaceTarget.empty() && targetStringsMatch(interfaceTarget, candidateTarget)) { return interface; } } } + // If no exact target match is found then return the first interface without a target + for (InterfaceElementPtr interface : interfaces) + { + // Look for interfaces without targets + const std::string& interfaceTarget = interface->getTarget(); + if (interfaceTarget.empty()) + { + return interface; + } + } return InterfaceElementPtr(); }