How to Optimize Your VR Application for Better Performance [10 Unity Optimization Tips]

By 
XR Bootcamp
January 31, 2022

How to Optimize Your XR Application for Better Performance [Unity Optimization]

There is a reason why VR game jobs seem more alluring to people, there is so much you can do in a VR application. Really the only limit is your imagination… or is it?

When it comes to building your VR application, you probably already have some amazing ideas to implement… but how do you optimize your VR application so it performs well?

You’ve probably already noticed the dimensions that a VR developer has to play with are more than your standard 2D developer. Which can lead to optimisation issues.

You see, the one thing that most VR developers are dealing with right now is the fact that this is a relatively new field of development - and some things that you might learn as a game developer might not fully apply here when it comes to virtual reality optimization (Unity VR Optimization).

In this new frontier of VR development, the one thing that can set you apart from your competitors is not being able to build great VR applications, but that those applications are optimized enough to run smoothly on their target devices.

What this article is going to cover:

For this article we will be primarily focusing on the Unity engine, since Unity for VR is one of the best choices to make. And also, if you're looking for VR development jobs, Unity is your best bet.

We’re also going to split optimization into two sections:

  1. Unity VR Optimization from a designer’s perspective.
  2. Virtual Reality Optimization from a developer’s perspective.

Virtual Reality Optimization from a designer’s perspective

Although it might seem that optimization is something that only developers should be concerned with, and they are… trust me. But optimization starts before the QA phase; it starts from the very beginning.
Say you can’t wait to finish your project and showcase it to the world - and potential employers.

However, if your application fails to meet the required FPS to run smoothly on a device, for example in Meta Quest 2 it's at least 72 FPS, it could cause motion sickness and discomfort for the user - rendering it pretty much useless.

So you see, we cannot afford to have a badly optimized application. Even if that application is a prototype that you have made for your portfolio. If you want recruiters to play your prototypes and see your skills without thinking of throwing off their headsets, that is.
As a designer coming into the XR industry, it’s essential to get to grips with Unity VR optimization as quickly ASAP. Why? Typically for designers with non-VR experience, it's not easy to get into the VR field. The thing that can set you apart from other designers is knowing how to prototype.
So, if you're looking for VR development jobs then you need to make sure your following these guidelines make your portfolio projects stand out.

• Level of detail

LOD, or level of detail, is a trick you’ll be familiar with, and it’s also something that is recommended for VR.
LOD works by switching between predetermined sets of models depending on the player’s distance from the object. Using this technique will keep the total number of polygons per scene relatively low and optimize the scene.
unity optimization

• Bump mapping

As a game developer, you know textures play an important role in the overall feel of the game, and we use a combination of textures and materials to give an illusion of depth and detail to models.
Well, while the traditional methods work well with a standard 2D screen, there are things to look out for when applying textures to models in VR.
For example, a normal map or a bump map is used to add surface detail, such as bumps and scratches to a model when light hits the object a certain way.
It works well on a 2D screen, but it’s not effective in VR as normal mapping cannot account for the use of stereoscopic lenses that are used in VR headsets.
Also, as a normal map is only generated from one viewpoint while the VR user has two viewpoints, it looks incorrect to the user. So, instead of a normal map, we should be using a height map.
The main difference between the two is that the height map factors in the viewer’s angle with the surface, and thus we can get much better results from using a height map - though bear in mind this is a performance-heavy process.

• Texture compression

For texture compression in Unity, go for ASTC. For fast prototyping, you could simply go to your project settings and in there go to texture compression and select ASTC - otherwise, you could also go and manually select each texture being used in the project and convert it to ASTC.
That second option might take a lot longer, but the upside is that this way you can keep certain textures without compression to retain their detail ( for example if you’re compressing textures it’d be wise to keep the texture used for the interface uncompressed).

• Mipmapping

Mipmapping is a technique where a high-resolution texture goes through a process of being downgraded and filtered.
By default, all textures in Unity for VR are selected for mipmapping, but still you can double check it by clicking on a texture and clicking advanced to see if ‘Generate Mipmaps’ is enabled.

• Trilinear filtering

Texture Filtering in Unity happens via mipmapping, as it blending between the mipmaps. However, we have some different options to choose from; point, bilinear and trilinear filtering. While point has basically no filtering, bilinear will sample the nearest mipmap.
Trilinear, on the other hand, will sample between the two nearest mipmaps and give us the smoothest transition. Thus, we should select trilinear filtering which we can do by selecting an image and then in the filter mode selecting the trilinear option.


unity optimization

• Lighting

Although this is a very complex topic, one rule of thumb is to use the least number of lights in the scene, and to make sure to use baked lighting as much as possible.

Unity VR Optimization from a developer’s perspective

As VR developers, it is important to start your development process with the right development structure. Refactoring your code during development is common.

But if you started off with a bad approach, well then it will only get worse and worse as the project builds up and it will lead to a situation where optimizing your application would seem harder than it was making it.

If you're following any Unity for VR tutorial then there is a high possibility they won't be going through these processes and in the end it might lead you to bad development habits.

• Scripting

Although scripting in itself is a very comprehensive topic that can take years to fully master, there are certain things to lookout for specifically when developing VR applications and virtual reality optimization (Unity VR Optimization).

• Disable script debugging:
Make sure to disable script debugging when testing out for virtual reality optimization (Unity VR Optimization), Also if you were using Debug.Log for debugging purposes then make sure to remove those as they themselves cause a performance impact in your application.
• Use structs instead of classes:
Now this can not be applicable in every scenario but when it comes to storing data for a short time, it's best to use structs as they are less performance intensive then classes.
• Object pooling:
Instead of Instantiating objects in your application and then later destroying them and repeating this cycle over and over, go for object pooling. Reuse those assets saving you those precious frames per second.
• Avoid update if possible:

When you build a class in Unity for VR, it automatically inherits from MonoBehaviour regardless if you want it to inherit the base classes properties or not. 

And when it comes to updating, if you have the habit of overusing updates in most of your classes then consider a different approach, as this could potentially bottleneck your application. Look for CPU Slicing as this will greatly help reduce performance issues.

Animation

It might seem as if animations should be something that designers should be concerned with but one needs to understand that animations are a vast topic of its own.

There are various kinds of animations, from procedural animations to motion capture animations to traditional animations. Here is a list of things to look out for.

• Reduce blend tree complexity:

Although blend trees in Unity is an amazing tool to traverse seamlessly from one animation to another. It does come with a performance cost. And since ideally these animations are traversed using some sort of animation script, it is advised to keep the blend nodes less than 6 for optimal performance.

• Limit animator use:

Although it might seem that in order to use animations we must have an animator component attached to that object. Well that is correct. But limit animators for only the characters. As for animating things like UI, there are other alternatives as we will mention below.

• Use tweening instead of animators

Try to make custom scripts and use tweening instead of animators. Especially when it comes to UI. It would be best to practice this out yourself but in case you wish to try out a plugin for tweening then you can check out Tween at the Unity asset store.

Physics

Physics is a very complex topic to cover, and depending on the type of project, the complexity can increase exponentially. That said there are still some checklists that one should follow to avoid any performance issues.

• Enable re-use collision callbacks:

Unity exposes callback events in MonoBehaviour such as OnCollissionEnter or OnTriggerEnter etc and these callbacks generally have a collision instance as a parameter. And whenever a collision callback occurs the collision object passed to it is created for each individual callback.
That means the garbage collector has to remove each object, now as devs usually use these callbacks multiple times, you can see how this would affect performance.
So, instead we can enable re-use collision callbacks which would then only use one instance of the collision for all these callbacks and help reduce garbage collection.

• Avoid mesh colliders:

Now I know how cool it looks when we use mesh colliders combined with physics. And while we can make some fun interactions out of it, we must understand that mesh colliders are really expensive in terms of performance.
A good alternative would be to use primitive colliders and combine them together to mimic the object they are attached to. Doing so will drastically reduce performance cost.

• Layer-based collision detection:

Layer-based collision detection is a way to make a gameobject collider with another gameobject that is setup to a specific layer. Make sure to utilize this feature and add in new layers for specific collision detections. So that there are no unnecessary computations happening.

Build size

Build size is an important factor to consider when we are talking about VR applications. As Oculus Quest or rather Meta Quest 2 applications have a certain limit when it comes to their size, we need to make sure that our applications don't exceed the max apk limit of 1 GB.

Not to mention the loading times during scene traversals. So here are some tips that can help you in virtual reality optimization (Unity VR Optimization).

• Check your build report:

In order to find out exactly which assets are the ones that are taking up most of the space, you can check your build report. Do so by first building your project, once your project is built go to the console window and right click and open Editor Log.
Find the build report at the bottom of the file. And there you can see which assets are using up the most of your application space. This will help you identify the areas where you can optimize your VR applications (Unity VR Optimization).

• Use crunch compression

For your texture images, it is recommended to use crunch compression to compress the images size, now that in turn does take some time to load up, but that's where you need to to observe if doing this is the right thing for you depending on your project, though often times it's the right approach.

• Tweak audio quality:

Besides textures, the other asset you should watch out for is Audio files. It is recommended to tweak the audio quality and reduce it slightly from 100 to below, usually it won't have any serious impact to the audio but keep in mind this is something that you would need to tweak individually.
Another thing to keep in mind is to not overuse decompress on load for the audio clip as that could have a negative impact on your applications performance.

Advice from an experienced VR game developer

VR App Optimization is an extensive topic, and it is something that is evolving at a rapid pace due to the fact that the software and hardware for VR development is improving and evolving with it.

And now with the announcement of Metaverse, there is going to be a high demand for VR development jobs and Unity will play a vital role in Meta Quest development and any future VR hardwares.

Developers are now focusing more on how applications were made on older consoles and the tips and tricks that were utilized at that time, and then amending them to help optimize applications for current gen VR devices such as the Oculus Quest, Oculus Quest 2, Meta Quest and so on.

Needless to say that learning how to optimize your VR application is perhaps the single most important thing right after learning how to build your VR applications.

In summary

Learning how to optimize your VR application projects is a necessary and a highly sought after skill to have when applying for VR game jobs. Though unfortunately it can take years to fully grasp all the tips and tricks required to hone these skills. 

As each project can have a different set of challenges and performance hurdles to solve, learning all this can take quite some time. 

Though luckily at XR Bootcamp, there is a completely separate course on Virtual Reality Optimization which covers these topics in great detail. Unlike any other VR Bootcamp, our courses cover every inch of the development lifecycle - from beginner level, to intermediate, to advanced.

Feel free to check out our courses and what we have to offer. Alternatively, feel free to join the XR Creators (free) discord server to ask any XR development question you may have to the >2500 XR developers actively engaging in the channel!

 

© 2021 XR BOOTCAMP. All Rights Reserved