Getting the fallback value from a UsdAttribute

Hey there!

Is there a way I can get the value of the fallback from a UsdAttribute on a composedStage? There is hasFallbackValue() which will tell me whether it has one, but I can’t seem to find a nice way to get the fallback value.

If no nice way is there any reasons why? The alternative being (from looking at the source) I’ll likely have to cycle through all the applied schemas on the prim and query them for the fallback values…(feels like it’s going to be slow) I can only assume this was done for a reason though, hence questioning whether there’s specific reasons as to why to avoid this. Especially with the PrimDefinition being purposefully hidden away as it is…

It doesn’t seem like it’d be too expensive, since the HasFallbackValue does 99% of the work, just it doesn’t return the Value any further?

bool
UsdAttribute::HasFallbackValue() const
{
    UsdPrimDefinition::Attribute attrDef =
        _GetStage()->_GetSchemaAttribute(*this);
    return attrDef && attrDef.GetFallbackValue<VtValue>(nullptr);
}

Cheers,
James

Hi James,

Sounds like a GetFallbackValue() might have been nice here for convenience. Not sure about the performance but as you mentioned most of the work is done in the attrDef anyway.

You can get the the fallbackvalue in this way though:

prim = attr.GetPrim()
primDef = prim.GetPrimDefinition()
defaultValue = primDef.GetAttributeFallbackValue(attr.GetName())

Cheers,
Dan

3 Likes

Perfect, I can’t believe I missed that GetPrimDefinition function on the UsdPrim!
Thank you Dan!

1 Like