Building performant applications for embedded systems can be quite challenging. In case of the Hololens, we are dealing with a relatively small amount of RAM and GPU power. (Hololens Graphics)
Unity is a great tool to build applications real quick without spending much time on the real basics. Hence, Unity already delivers a pre-defined set of functionality, whether we need it or not.
While I was building my first application for the Hololens with Unity, I quickly noticed huge performance impacts while executing simple tasks. Not only I didn’t configure Unity properly, but also not much effort was made to “code” efficient. This article covers some basic tweaks to increase your Hololens project performance with Unity.
Captain Obvious Tips
It may sound simple and obvious, but as a nine to five Unity developer, not much effort is made to optimize the scene itself, without even starting to tweak the Unity settings itself.
- Keep the amount of gameObject at a total minimum.
- Destroy or at least Disable unused gameObjects.
- Avoid Update and FixedUpate calls. Try to add as much logic into one Update function as possible, instead of reusing the same script over and over again.
- Try to use the new ECS System Unity just came up with.
- Use shaders carefully. Less is more in terms of performance.
- Use low LOD models and improve the overall appearance with the texture.
- Avoid canvas elements.
- Prefer mobile shaders over desktop shaders
- Always ask yourself: “Do we really need this script/shader/gameObject”?
- Use the latest Unity and HoloToolKit
Let’s say we already optimized our scene as much as we can afford, we still have some options left.
- I do not recommend to use lights at all, but mark static gameObjects as static and pre-bake as many lights as possible to avoid real-time rendering.
- Avoid casting soft- or hard shadows
- In the “Lighting” window, use following environment light settings for the best performance
- Prebake Collision Meshes and Optimize Mesh Data.
- Select the prefabs you are using the most to speed up the initialization process.
- Enable Vertex Compression as well.
- Set “Stereo Rendering Mode” to “(Fastest)“
- Not shown in the screenshot, but disable Accelerometer Frequency if not needed.
- Configure the collision matrix in a way you need it. Disable all unnecessary collision checks.
- Disable 2D collision. (Only possible if no 2D collider components are in use)
- Avoid Mesh-Colliders and try to apply the most simple colliders. Such as BoxCollider or ShpereCollider.
- Make use of Layers and only let gameObjects collide which should be collidable.
The configuration of the quality settings depends on the application. Therefore, try to tweak the settings as much as possible and find the optimal minimum for the application.
- Reduce Light Count
- Lower the texture quality
- Anisotropic Textures
- Soft Particles
- Real-time Reflection Probes
- V-Sync: Don’t Sync
Example of a compromise configuration between performance and quality
Be aware that HoloToolKit adds a lot of bloatware which is mostly not required.
“Apply Mixed Reality Scene Settings” adds some gameObjects we possible don’t need. Thus, iterate over each element and it’s attached scripts to perform some additional optimization steps.
Don’t forget to bake the light before building a release build 🙂