Is there any unity API for android to dynamically select graphics API like Vulkan and OPENGLES3 based on something like device name or android version at game app launch? If no, how to achieve this today without export entire project to android studio? And also will official implement it at 2023.2 cycle, 2024 or later so unity user no longer needs to write a lot of custom code just to achieve this requirement?
#API to dynamically select graphics API based on something at game app launch
1 messages · Page 1 of 1 (latest)
Hey there! you can totally do that by specifying Unity start up arguments, you can find out more at https://docs.unity3d.com/Manual/android-custom-activity-command-line.html
Yeah sure it's a bit of a manual process plugging in your own device/version requirements, but you don't need to export to Android Studio
Is there something similar to PC to check DX12 compatibility etc?
you can certainly pass command line arguments to any standalone player, but I'm not sure how you would hijack the startup on Windows as I'm a mobile person, let me get back to you on that https://docs.unity3d.com/Manual/PlayerCommandLineArguments.html
Thanks!
I know about the arguments for desktop, but right now I mostly see people on steam giving a prompt up front. Automatic would be way better
🧐 Any plan to further improve it until dun need to write single line of java code?
🤔 Btw I think still need to write aar plugin at android studio and drag into unity project to make it works? Is that possible to put java code into unity project and just works without aar plugin?
You don't need AAR plugin, simply do this:
- Create OverrideExample.java and place it in Unity project, copy contents from documentation Neil posted
- In Unity project, enable Custom Main Manifest template in PlayerSettings
- Open Assets\Plugins\Android\AndroidManifest.xml and replace com.unity3d.player.UnityPlayerActivity -> com.company.product.OverrideExample, that way your activity will be launched instead
- That's it
Thanks for the reply. I will try it.
On steam you can provide multiple command lines and it will show a dialog to choose, if that's what you're talking about.
Yep! Would be nice if that could be automatic (check GPU generation/release year and dx12 compatibility and select dx12 or dx11 accordingly)
that's how Auto Graphics API selection generally works. It first checks for support for the top API, if it's supported, uses it. If it's not, it will fallback to the next one. So what you'd do is drag DX12 to the top of the API selection list and DX11 right before it in Player Settings.
Of course if you want to customize it, you can select "Generate Visual Studio solution" option in the build window when building for Windows, and write code there to do your custom detection logic and pass according command line parameter to the UnityMain() function.
But auto api hides the APIs being built, so you don't really know what is used in editor
right, that was a wrong choice of words from me. There are two things at play:
- Graphics API list. For every built game, Unity serializes that list and it works as I described: Unity tries APIs one by one from top to bottom until it finds one it can use (or displays a dialog message it cannot use any);
- Auto graphics API checkbox in player settings. Enabling it will choose whatever default list for each platform that we determined it should be. For windows that only consists of DirectX 11 today. So if you want to enable DX12 first and DX11 second, you need to uncheck that checkbox, add DX12 and drag it to the top.
Got it, thanks!
So if dx12 is at the top and then dx11 it will fall back to dx11.
Didn't know that! Thought it had to be explicitly stated
It is explained in https://docs.unity3d.com/Manual/GraphicsAPIs.html but maybe it's not very clear