# Stage variables for layer offset

**URL:** <https://forum.aousd.org/t/stage-variables-for-layer-offset/2379>\
**Category:** USD\
**Tags:** beginner\
**Created:** [April 16, 2025, 1:52pm UTC](https://forum.aousd.org/t/stage-variables-for-layer-offset/2379 "2025-04-16T13:52:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![josephfernando](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@josephfernando](https://forum.aousd.org/u/josephfernando)\
**Post date:** [April 16, 2025, 1:52pm UTC](https://forum.aousd.org/t/stage-variables-for-layer-offset/2379/1 "2025-04-16T13:52:05Z")

</div>

Hello!

I’m trying to prototype a workflow where we can to time offset our caches (references/payloads) based on stage variables. The idea is to have different layers with different offsets values so our caches look different when each of them are sublayered.

I was trying to get int variable expression working in a simple stage like below and I can’t seem to get them working, getting syntax error on the offset variable. Is it even possible to do something like this? Open for any suggestions, thanks in advance 🙂

```auto
#usda 1.0
(
    expressionVariables = {
        int64 FRAME = 5
	}
)

def Xform "root"
{
    def "FX5" (
        prepend references = @cache.usda@</cube1> ( offset = `${FRAME}` )
    )
    {
    }
}

```

Cheers,  
Joseph

---

<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:** [April 18, 2025, 7:36am UTC](https://forum.aousd.org/t/stage-variables-for-layer-offset/2379/2 "2025-04-18T07:36:57Z")

</div>

I don’t believe this is currently possible

See the documentation here [USD Variable Expressions — Universal Scene Description 25.02 documentation](https://openusd.org/release/user_guides/variable_expressions.html)

> Variable expressions can currently be used in:
> 
> - Asset paths (including sublayer, reference, and payload asset paths as well as asset-valued attributes and metadata).
> - Variant selections.

---

<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:** [April 19, 2025, 12:41am UTC](https://forum.aousd.org/t/stage-variables-for-layer-offset/2379/3 "2025-04-19T00:41:49Z")

</div>

Probably not workable for your use case, but if you have a limited number of frame offsets, I verified that the following works, without error in all cases, as long as `FRAME` is defined to _something_ . If it’s set to a value that’s outside your range, I set it up to bring in the reference with no offset, but you can do anything you want there.

```auto
#usda 1.0
(
    expressionVariables = {
       int FRAME = 5
    }
)

def "MyPrim" (
   prepend references = [ @`if(eq(${FRAME}, 1), "test1.usda")`@(offset = 1),
                          @`if(eq(${FRAME}, 2), "test1.usda")`@(offset = 2),
                          @`if(eq(${FRAME}, 3), "test1.usda")`@(offset = 3),
                          @`if(or(lt(${FRAME}, 1), gt(${FRAME}, 3)), "test1.usda")`@]
)
{
}

```

For completeness, `test1.usda` (`usdcat --flatten` is a quick way to observe how the timeSamples move in response to different `FRAME` values in the root layer):

```auto
#usda 1.0
(
    defaultPrim = "hello"
)

def Xform "hello"
{
    double3 xformOp:translate.timeSamples = {
      0: (1, 2, 3),
      1: (4, 5, 6),
      2: (7, 8, 9),
    }
    uniform token[] xformOpOrder = ["xformOp:translate"]

    def Sphere "small"
    {
        float3[] extent = [(-2, -2, -2), (2, 2, 2)]
        color3f[] primvars:displayColor = [(0, 0, 1)]
        double radius = 2
    }

    def Sphere "big"
    {
        float3[] extent = [(-2, -2, -2), (2, 2, 2)]
        color3f[] primvars:displayColor = [(0, 0, 1)]
        double radius = 20
    }
}

```

---

<div class="post-metadata">

**Author:** ![josephfernando](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@josephfernando](https://forum.aousd.org/u/josephfernando)\
**Post date:** [May 14, 2025, 12:02pm UTC](https://forum.aousd.org/t/stage-variables-for-layer-offset/2379/4 "2025-05-14T12:02:01Z")

</div>

Sorry missed to reply on this thread..  
Interesting way of using conditions @spiff !  
I’ll take note of this to use elsewhere, but in this case I don’t think it’s possible to list all the frames.  
I’m now using composition arc effectively to list-edit my references with new offset values..  
Thanks a ton for giving this a try 🙂
