Render Models
Since your whole field of vision is covered when immersed in Virtual Reality it's helpful to have virtual representations of the controllers you're holding. SteamVR provides an easy way to get not just a general controller model but models with individually actuating components. So when you pull the trigger on your controller in real life you can see it pull in the virtual world as well. This helps with usability as well as strongly encourages the feeling of presence.
The Component
Both the Interaction System and the Simple Sample scenes have rigs that use render models. In the Simple Sample scene look in the [Camera Rig] prefab, you'll find Controller (left) and Controller (right). These GameObjects have a SteamVR_Behaviour_Pose component on them which sets the position and rotation of the transform. Under those objects you'll see GameObjects called Model which hold our SteamVR_RenderModel component. It has a few members:
- Index - this is the "tracked device index" for the controller. It's an integer id used by the render model system to identify the controller to the underlying system. In previous iterations of SteamVR this was also used to access inputs on that controller, but now that is done through the Input System.
- Model Override - Generally for testing purposes you can specify what model you would like to display instead of dynamically assessing the type of device connected.
- Shader - If you would prefer to use a different shader to render the model you can specify it here. By default, Unity's Standard Shader is used.
- Verbose - Will output debug logs to tell you what's happening with the script
- Create Components - Creates individual GameObjects for each component where available
- Update Dynamically - Will move the individual components inline with their physical counterparts.
Attaching Objects
Developers commonly want to attach GameObjects to specific points on controllers. For this we have placed a GameObject called "attach" under each part of the controller that is centered on the part in question. For ease of access you can get access to the SteamVR_RenderModel script and call GetComponentTransform(string componentName) which will return \a Transform (without doing any GC alloc). The componentName parameter here is case sensitive so make sure you pass in the component name exactly as it appears in the hierarchy at runtime.
Notes
The SteamVR_RenderModel component needs to be on the same gameobject as something that will set its Index. In the [CameraRig] prefab this is done by the SteamVR_Behaviour_Pose script.