Modify Stage with USDRT without WriteToStage

I am trying to modify many prims at once in the scene using USDRT. The issue I have is that, unless I call stage.WriteToStage after applying the modifications, the scene does not get updated. From looking at the documentation and examples ( Working with OmniHydra Transforms — usdrt 4.0.5 documentation (omniverse-docs.s3-website-us-east-1.amazonaws.com)), it doesn’t seem to be necessary to call WriteToStage for the scene to update.

I made an example with the following code:

from usdrt import Usd, UsdGeom, Gf, Rt, Vt, Sdf

stage = Usd.Stage.Attach(omni.usd.get_context().get_stage_id())
prim: Usd.Prim = stage.GetPrimAtPath(Sdf.Path("/World/Cube"))

if not prim.HasAttribute(UsdGeom.Tokens.primvarsDisplayColor):
   prim.CreateAttribute(UsdGeom.Tokens.primvarsDisplayColor, Sdf.ValueTypeNames.Vector3fArray, False)
   color = prim.GetAttribute(UsdGeom.Tokens.primvarsDisplayColor)

color.Set(Vt.Vec3fArray([Gf.Vec3f(0, 1, 0)]))

stage.WriteToStage()   # Without this line, the cube's color does not change

Is WriteToStage necessary? If not, what may I be doing wrong?

Let me find out and get back to you shortly.

Here is an update.

I did manage to modify prims without WriteToStage on an existing USD file. So, I thought maybe if the opened stage had unsaved changes, that perhaps those unsaved prims may not be modified without WriteToStage. But, I tried the following:

  1. Open New Stage
  2. Create Cube
  3. Save USD
  4. Modify Cube with USDRT

Still, nothing changed in the scene. The only difference I see between the created cube and those objects I could modify without WriteToStage was that the Cube was nested under the World (defaultPrim) prim, whereas the other objects were under the Environment prim.

I also printed the attributes of the Cube after I assigned new values, and they are indeed changing. Not sure why they are not being updated in the scene.

Anyways, I’m not really stuck anymore since the objects I needed to modify are actually being visualized, but maybe there is a bug somewhere?

Glad to hear. I will look into this as a possible bug but it sounds like using the World Prim fixed it.