Oculus compiler #define directive

Hi,

I’m developing for native Oculus support and I need to get a way to detect if OVR plugin is available or not in a project from a compiler directive in C# scripts. I’ve searched but can’t find any info about it. Is it possible ?

If yes, i’d like to know what’s the corresponding #define for OpenVR.

Thank you very much!

There isn’t one for Oculus for sure, you’ll have to create your own. You can always tell the non Unity defines in the list in player settings to double check. I’m not sure on Open VR but I doubt there is one. There certainly are runtime checks you can do based on the virtual reality sdks but not compile time.

Creating your own for any purpose is fairly straightforward though.

Thank you for your answer!

How one can actually confidently release a package over the Asset Store that is compatible with both Oculus native and Steam VR but without requiring the customer to get both SDK as to avoid throwing errors everywhere ?

Either use custom defines or only use the VR features that Unity provides.

1 Like

Creating your own define is fairly straightforward. Just use PlayerSettings.SetScriptingDefineSymbolsForGroup to add what you want.

1 Like

Many thanks to you both for putting me on track!

* Notice: This is not an attempt to ‘shove something down your throat’, it’s simply meant to be helpful *

I did make an asset for this so you can set up custom defines in GUI and also enable/disable them via code:
CustomDefineManager.DisableDirective(“Oculus”);
CustomDefineManager.EnableDirective(“Oculus”);

Here’s my pack:

And some free ones:

I don’t think you have to do that, in fact the people that think that asset authors are just used car salesman will probably complain more with attention drawn to it in bold. This also isn’t related to this post but a recent one just in case someone only reads this thread and is confused.

It’s been my standard operating procedure for years to tell the user how to do it in Unity and if I have a product also mention that. As long as you tell them the steps to do so in Unity I think 99% are happy. The 1% are never happy it’s best to move on and not waste your time.

There is nothing wrong with your old behavior, I would get rid of the notice.

1 Like