DAZ Studio 6 SDK: Safe way to duplicate and assign DzUberIrayMaterial to another DzShape?
umblefugly
Posts: 131
In DAZ Studio 6 / 2026 SDK, what is the supported way to duplicate a DzUberIrayMaterial and assign it to another DzShape with addMaterial() or replaceMaterial() so the shader network is preserved and ownership/lifetime is safe?
- DzElement::doDuplicateElement() returns DzElementPtr, and script replacement fails with DzTSharedPointer<DzElement> ... to DzMaterial*.
- DzMaterial::duplicateOrDefaultMaterial() returns DzMaterialHandle; calling it from C++ and using handle.get() crashed inside cloneMaterialPreserveNameCxx.
- Manual DzDefaultMaterial copying works structurally but loses Iray glass shader fidelity.

Comments
I figured it out and ill leave this summary for anyone else having the issue migrating from DS 4.24.x.x to DS 2026:
C++ creates DzFacetShape for each shard.
C++ adds initial materials with shape->addMaterial(...):
While emitting shard facets, C++ activates material indices directly:
After scene nodes are created, C++ calls the embedded DAZ Script material pass.
Script resolves the original source node by label and gets:
srcShape.getMaterial(mi)
For each source material, script creates a DAZ6 material duplicate with:
srcMat.duplicateOrDefaultMaterial(ctx)
Script finalizes the DzElementDuplicateContext:
createAlaises/createAliases, createERC, doResolve, doFinalize
Script gets the shard placeholder material at:
shardShape.getMaterial(mi + 2)
Script replaces it:
shardShape.replaceMaterial(oldMat, duplicatedMat)
The critical DAZ6 change is using duplicateOrDefaultMaterial() instead of doDuplicateElement() or manual DzDefaultMaterial property copying. That preserves DzUberIrayMaterial instead of downgrading to DzDefaultMaterial.
Some wording is specific to my plugin, but hopefully you get the gist :D