# Quirk with Value Resolution

**URL:** <https://forum.aousd.org/t/quirk-with-value-resolution/1875>\
**Category:** USD\
**Created:** [September 25, 2024, 12:55am UTC](https://forum.aousd.org/t/quirk-with-value-resolution/1875 "2024-09-25T00:55:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tymon](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@Tymon](https://forum.aousd.org/u/Tymon)\
**Post date:** [September 25, 2024, 12:55am UTC](https://forum.aousd.org/t/quirk-with-value-resolution/1875/1 "2024-09-25T00:55:10Z")

</div>

While developing a pipeline for version management of lookdev within a shot we ran into a peculiar behaviour where a variant selection was being made in a referenced layer, Usd reports the correct variant selection in the composed stage, but the values being set by the variant are not coming through.

I’ve managed to reproduce the problem with the following simplified layer (this is using usd-23.08):

```auto
#usda 1.0

def "Element" (
    add references = [
        </LookSelectionLayer/Element>,
        </LookdevLayer/main>,
    ]
)
{
}

def "LookSelectionLayer"
{
    over "Element" (
        variants = {
            string look = "variantA"
        }
    )
    {
    }
}

def "LookdevLayer"
{
    def "main" (
        prepend references = </LookdevLayer/ __BASE_LOOK__ >
        prepend variantSets = "look"
    )
    {
        variantSet "look" = {
            "variantA"
            {
                def "LookdevInterface"
                {
                    string foo = "variantA value"
                }
            }
        }
    }

    def " __BASE_LOOK__"
    {
        def Scope "mtl"
        {
            def Material "MyMaterial" (
                prepend inherits = </LookdevLayer/ __BASE_LOOK__ /LookdevInterface>
            )
            {
            }

        }

        def "LookdevInterface"
        {
            string foo = "base value"
        }
    }
}

```

If you query the selected look variant in the composed stage for `/Element` it reports “variantA” like I expect:

```auto
>>> print(stage.GetPrimAtPath("/Element").GetVariantSet("look").GetVariantSelection())
variantA

```

However, when you get the value of `/Element/mtl/MyMaterial.foo` it returns “base value” where I’m expecting it to be “variantA value”:

```auto
>>> print(stage.GetObjectAtPath("/Element/mtl/MyMaterial.foo").Get())
base value

```

I’ve looked at the PrimIndex dot graph and the variant opinion is listed as #6 and the base look’s LookdevInterface opinion is listed as #9 so the variant opinion _should_ be winning. However if you inspect the property stack for the attr, it only contains a single entry from the base look’s LookdevInterface:

```auto
>>> stage.GetObjectAtPath("/Element/mtl/MyMaterial.foo").GetPropertyStack()
[Sdf.Find(..., '/LookdevLayer/ __BASE_LOOK__ /LookdevInterface.foo')]

```

So somehow the variant’s AttributeSpec is getting lost.

Doing any of the following will give the expected “variantA value” value:

- select `look="variantA"` directly on `/Element` rather than via a reference

```auto
>>> stage.GetPrimAtPath("/Element").GetVariantSet("look").SetVariantSelection("variantA")
True
>>> print(stage.GetObjectAtPath("/Element/mtl/MyMaterial.foo").Get())
variantA value

```

- remove the LookdevInterface indirection and just set `foo` directly on MyMaterial
- remove the intermediate “mtl” prim from the layer (this one was quite surprising!)

Am I misunderstanding something about value resolution or is this a bug?

---

<div class="post-metadata">

**Author:** ![dhruvgovil](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/dhruvgovil/32/3_2.png) [@dhruvgovil](https://forum.aousd.org/u/dhruvgovil)\
**Post date:** [September 27, 2024, 5:40pm UTC](https://forum.aousd.org/t/quirk-with-value-resolution/1875/2 "2024-09-27T17:40:15Z")

</div>

Out of curiosity, how are you seeing the PrimIndex dot graph?

I believe this is because in LIVRPS, the Inheritance will win out over the Variant. (I before V).

---

<div class="post-metadata">

**Author:** ![Tymon](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@Tymon](https://forum.aousd.org/u/Tymon)\
**Post date:** [September 30, 2024, 2:43am UTC](https://forum.aousd.org/t/quirk-with-value-resolution/1875/3 "2024-09-30T02:43:44Z")

</div>

> [@dhruvgovil](#):
>
> Out of curiosity, how are you seeing the PrimIndex dot graph?

```auto
prim_index = prim.ComputeExpandedPrimIndex()
dot_graph_file_path = ...
prim_index.DumpToDotGraph(dot_graph_file_path )

```

That dumps the graph to a text file which you can then convert to a .svg using the `dot` command line tool from graphviz: [Command Line | Graphviz](https://graphviz.org/doc/info/command.html)

> [@dhruvgovil](#):
>
> I believe this is because in LIVRPS, the Inheritance will win out over the Variant. (I before V).

This is only true if there were a direct opinion on `/Element/LookdevInterface`. LIVRPS is much more complex than “I before V” when dealing with nested composition arcs. If you look at the PrimIndex you can see that the `/Element/LookdevInterface` entry at #1 has no spec which means it is not contributing any opinions. The `/LookdevLayer/ __BASE_LOOK__ /LookdevInterface` entry (where the “base value” value is coming from) is #9 in the prim index which is weaker than the variant entry at #6.

Also, even if “I before V” were the reason, I would still expect to see the variant opinion in the PropertyStack but it’s just completely missing which leads me to believe it’s a bug.

---

<div class="post-metadata">

**Author:** ![dhruvgovil](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/dhruvgovil/32/3_2.png) [@dhruvgovil](https://forum.aousd.org/u/dhruvgovil)\
**Post date:** [September 30, 2024, 5:03am UTC](https://forum.aousd.org/t/quirk-with-value-resolution/1875/4 "2024-09-30T05:03:01Z")

</div>

It might be worth uploading the dot graph here (you might need to zip it)

But yeah it does sound like a bug. Might be worth filing an issue on the repo as well just for tracking purposes

---

<div class="post-metadata">

**Author:** ![spiff](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/spiff/32/22_2.png) [@spiff](https://forum.aousd.org/u/spiff)\
**Post date:** [September 30, 2024, 8:55pm UTC](https://forum.aousd.org/t/quirk-with-value-resolution/1875/5 "2024-09-30T20:55:50Z")

</div>

@Tymon , that does defy my expectation, as well. There has been some substantial work (including bugfixes involving ancestral variants) in the past year, so could I possibly request you test in 24.08 before filing a bug? You should be able to use the latest pypi usd-core package if it’s inconvenient to build.

Thanks!

---

<div class="post-metadata">

**Author:** ![Tymon](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@Tymon](https://forum.aousd.org/u/Tymon)\
**Post date:** [October 1, 2024, 7:43pm UTC](https://forum.aousd.org/t/quirk-with-value-resolution/1875/6 "2024-10-01T19:43:43Z")

</div>

Ah! It does work in 24.08. I should have tried it there first.

@spiff, if we wanted to backport the bug fix to 23.08 ourselves, do you happen to know any specific commits we could look at and how difficult that might be? I suppose if there have been large refactors it could be quite involved…

---

<div class="post-metadata">

**Author:** ![spiff](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/spiff/32/22_2.png) [@spiff](https://forum.aousd.org/u/spiff)\
**Post date:** [October 1, 2024, 9:20pm UTC](https://forum.aousd.org/t/quirk-with-value-resolution/1875/7 "2024-10-01T21:20:20Z")

</div>

Would need to research to find the specific commits, which are all in pxr/usd/pcp, but I’d estimate the difficulty of selectively pulling to be reasonably high. We’ve been doing **alot** of work in pcp, and IIRC, there were two “fixes” related to ancestral variantSets (the second one fixing a previously untested case that the first broke), but inbetween those two fixes was a pretty significant change for dynamic payloads to be able to take variantSets (and other composition) into account when computing the parameters to the payload.

---

<div class="post-metadata">

**Author:** ![Tymon](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@Tymon](https://forum.aousd.org/u/Tymon)\
**Post date:** [October 1, 2024, 9:42pm UTC](https://forum.aousd.org/t/quirk-with-value-resolution/1875/8 "2024-10-01T21:42:18Z")

</div>

I suspected as much. Moving to 24.08 isn’t an option for us in the short term unfortunately so we’ll discuss internally and see whether we think it’s worth it to try and backport any fixes. We’ll probably just work around the issue for now by sublayering the LookSelectionLayer rather than referencing it (we were probably going to end up doing that anyway).

Thanks for your help!
