Scripting / VoltCS
VoltCS
VoltCS is how you script ParelVR worlds: C# behaviours, compiled by the SDK and run safely on every player's client.
What it is#
You write ordinary-looking C# classes that derive from VoltBehaviour. When you build the world, the SDK's compiler turns them into Volt bytecode, which ParelVR runs in a sandbox. Scripts can only reach the API listed in this reference: the ParelVR.Volt namespaces plus a safe part of Unity and .NET. They cannot touch files, the network (except through VoltWeb) or anything else outside the world.
Current API: 1.6, with 106 types, 1,330 members and 50 events.
World scripts in one minute#
- ParelVR SDK > Volt > Create Volt Script makes a script that derives from
VoltBehaviour. - Put it on an object in your world scene and press Play: the script runs in the Volt simulator.
- ParelVR SDK > Volt > Build & Upload compiles the scripts, builds the world and uploads both.
Next: Your first script.
No code needed for the basics
Doors between worlds, avatars on pedestals, sounds behind walls and a menu full of toggles and sliders all work without a single script. See World portals, Avatar pedestals, 3D audio and World Menu. Scripts are for everything beyond that.
Tools#
Everything is under ParelVR SDK > Volt:
| Tool | What it does |
|---|---|
| Create Volt Script | A new script from the template. Also in Assets > Create > ParelVR > Volt Script. |
| Compile | Compiles every script and lists errors in the Volt Console. |
| Console | Logs from VoltDebug and compiler messages. |
| Debugger | Breakpoints and stepping through scripts in play mode. |
| Profiler | Time and instructions each script uses per frame. |
| API Explorer | Browse the whole API inside Unity. |
| Graph Editor | Build a script from nodes; Generate writes the VoltCS for you. |
| Hot Reload | Ctrl+Alt+R. Saving a script in play mode swaps it into the running world, keeping field values. |
| Network Cost | Bytes per update and per second of every script's synced fields. |
| Player Parameters | Values every player carries in your world. See Player Parameters. |
| Multi-Client Play Mode | Test with several players. See Multi-client testing. |
| Test in VR | Play mode in a headset. |
| Validate World | Runs the world checks without building. |
| Build World, Build & Test, Build & Upload | Build steps. |
What is different from Unity C#
- Derive from
VoltBehaviour, notMonoBehaviour, and override its events (OnStart,OnUpdate,OnInteract...) instead of Unity's magic methods. - Use the Volt types for world objects:
VoltGameObject,VoltTransform,VoltRigidbodyand so on. Fields of Unity component types are bound to their Volt wrappers. - Log with
VoltDebug.Log. - Only the members in this reference compile. The compiler tells you when you use something outside it.
- Scripts have limits on time, memory and network use.
