---
name: clone-environments
description: Replicate a USD scene subtree into many parallel environments for RL-style training. Use when setting up batched simulation with cloned environments, or replicating physics scenes for reinforcement learning.
---

# Clone Environments

Use the clone API to replicate sub-sections of a USD scene.

Important: cloning does not author new prims into the USD stage (and does not modify the USD file). Instead, ovphysx uses
the PhysX replication to create the replicated hierarchies in the internal runtime scene representation used for simulation.
The source hierarchy must exist in USD, but the replicated copies only exist in the internal representation.

## Python

```python
from ovphysx import PhysX

physx = PhysX(device="cpu")
physx.add_usd("scene.usda")

# Clone /World/envs/env0 to env1, env2, env3
targets = ["/World/envs/env1", "/World/envs/env2", "/World/envs/env3"]
physx.clone("/World/envs/env0", targets)
```

Full sample:
- `samples/python_samples/clone.py` (wheel)

## C

```c
ovphysx_string_t targets[3] = {
    ovphysx_cstr("/World/envs/env1"),
    ovphysx_cstr("/World/envs/env2"),
    ovphysx_cstr("/World/envs/env3"),
};
ovphysx_enqueue_result_t r = ovphysx_clone(
    handle, ovphysx_cstr("/World/envs/env0"), targets, 3);
```

Full sample:
- `samples/c_samples/clone_c/main.c` (SDK)

## Requirements

- Source hierarchy must exist in the loaded USD stage.
- Source prims must have physics components.
- Target paths must not already exist.
- Collision isolation between clones is configured through USD scene properties (collision groups, filtering), not through the clone API.

## Key APIs

| Python | C |
|--------|---|
| `physx.clone(source, targets)` | `ovphysx_clone()` |

## References

- Docs: `docs/tutorials/cloning.md`
- Python sample: `samples/python_samples/clone.py` (wheel)
- C sample: `samples/c_samples/clone_c/main.c` (SDK)
