USD Edit targets and Edit contexts directly modify USD Layers, according to some stage.
Every USD stage has a USD Layer where, by default, all your
opinions go. It's called the "root" Layer and is accessed using
stage.GetRootLayer()
/ stage->GetRootLayer()
.
All an Edit Target / Edit Context does is it tells USD "from here on, any opinions will go in this other Layer instead of the root Layer".
Only USD Layers in the USD's LayerStack are able to be edit targets. In other words, the layers must be available using the Sublayer composition arc. You can't apply an edit target to a referenced Layer, for example.
{
pxr::UsdEditContext context {main_stage, inner_stage->GetRootLayer()};
auto sphere = pxr::UsdGeomSphere(main_stage->GetPrimAtPath(pxr::SdfPath{"/root/sphere"}));
sphere.GetRadiusAttr().Set(10.0);
}
main_stage->SetEditTarget(pxr::UsdEditTarget(inner_stage->GetRootLayer()));
auto sphere = pxr::UsdGeomSphere(main_stage->GetPrimAtPath(pxr::SdfPath{"/root/sphere"}));
sphere.GetRadiusAttr().Set(5.0);
with Usd.EditContext(main_stage, inner_stage.GetRootLayer()):
sphere = UsdGeom.Sphere(main_stage.GetPrimAtPath("/root/sphere"))
sphere.GetRadiusAttr().Set(10)
main_stage.SetEditTarget(Usd.EditTarget(inner_stage.GetRootLayer()))
sphere = UsdGeom.Sphere(main_stage.GetPrimAtPath("/root/sphere"))
sphere.GetRadiusAttr().Set(5)