Replicator only loads 1 random usd from list

Hello,
I am trying to randomly load a different USD file from a list or folder. I have tried using rep.randomizer.instantiate but it picks 1(if I set the size to 1) at random and then never changes it for the following frames. I have also tried setting up some sort of randomizing rep.create.from_usd but I always get a “References.AddReferences(…” warning.
Instantiate works just fine with Nvidias trees and rocks and create.from_usd works either as a single line or for loop.
So what is the best way to load a single, relatively complex(think robot or landscape) USD randomly per frame?

Hi @lhagan87 I think we chatted about this on discord, but I’ll answer here if others have the same question.

Here’s a simple script for loading usd files in a directory, and instantiating them (and destroying them) each frame. In this example I tested this with three usd files, a cube, a cone and a sphere, and it will pick a random usd instantiate it, and destroy it, rinse repeat each frame.

Also, as you noted, running preview() doesnt unload the one it generated for the preview.

import omni.replicator.core as rep

# Get usds from a directory path
usd_directory = r'C:/replicator-examples/load_usd'
usd_files = rep.utils.get_usd_files(usd_directory, recursive=False)
print(usd_files)

with rep.new_layer():
    with rep.trigger.on_frame(num_frames=10, rt_subframes=20):
        # Instantiates a USD randomly from the files list
        # Unloads previous one on next frame
        rep.randomizer.instantiate(paths=usd_files,size=1, use_cache=False)
1 Like