Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

Unity tip: Enable IL2CPP for performance gains

l0g1kl0g1k Posts: 47 Oculus Start Member
I only recently realised I could use this feature, and turning it on reduced the CPU time for the OvrAvatar update loop from 1.5 ms to around 0.8 ms  - saving around 0.7 ms per avatar on an S6. If you don't know, it translates C# to native binaries. There is a lot of really slow MS native inter-op code in the Avatar SDK that seems to have benefited a lot from that.

Hopefully this helps someone else. Make sure you use a late-2017 or newer Unity as there were lots of bugs floating around before then I think.

PS: Another tip for lowering processing on lower end devices is that if the user does not have a controller connected, and is alone in the scene, you can disable OvrAvatar completely and save a bit of time, since the avatar is likely not doing anything in the scene at that point anyway (unless you have other cameras for some reason).


  • Preston_JPreston_J Posts: 23 Oculus Start Member
    I will for sure try this.   I'm always looking for ways to optimize.   My game right now maintains 90 FPS, but the headroom is around 3% to 15% with an NVIDIA 1070.   And on my transition scenes I'll disable the OVRAvatar completely.   Thanks for the tips.
  • l0g1kl0g1k Posts: 47 Oculus Start Member
    Thanks for your feedback and contribution to this forum!

    As follow-up there is some small change needed to the AvatarSDK usage to support this

    Find the method "MicFilter" and add this attribute " [MonoPInvokeCallback(typeof(CAPI.FilterCallback))]". (Add "using AOT;" to the file)

    Please note the MicFilter content might have changed by the time you read this so don't copy/paste; just find it and add the attribute like so
    public static void MicFilter(short[] pcmData, System.UIntPtr pcmDataLength, int frequency, int numChannels)
            float voiceMax = 0.0f;
            float[] floats = new float[pcmData.Length];
            for (int n = 0; n < pcmData.Length; n++)
                float cur = floats[n] = (float)pcmData[n] / (float)short.MaxValue;
                if (cur > voiceMax)
                    voiceMax = cur;
            voiceCurrent = voiceMax;

Sign In or Register to comment.