- Home /
Selecting at runtime the graphics API
I know I can in the player settings control the graphics api to include. such as opengles2 and metal etc.
However for easy QA builds I want to be able to select or override metal builds with opengles2.0 or 3.0 versions using Settings.bundle root.plist then during launch automatically set the graphics api to use.
I've only been able to find in PlayerSettings scriptAPi any method of controlling the choosing of an api. I can of course use Systeminfo,graphicsDeviceType to print out the choice but I cannot quite figure out if its possible to change the API selection on launch.
-andi
I'm answering my own question. Not sure if this is the best way to do it..
I've modified the UnityAppSupport+rendering.mm file that was generated by the build. I've effectively modified the SelectRenderingAPIImpl function with a couple of lines of code that reads from standarduserdefaults a multi-value that is mapped from 0 to 2. This effectively swaps out values in the array if all 3 are added. So if gles2 is selected it will move that from the array tail. Now this only works if adding all rendering api's to the list for iOS.
// reprioritize array by swapping index 0 for the specified
NSInteger item = [[NSUserDefaults standardUserDefaults] integerFor$$anonymous$$ey:@"gfxapiSetting"];
int temp = apis[0]; apis[0] = apis[item]; apis[item] = temp;
the code is injected just before the for/loop iteration checking for the version to use. I dont need to check item existing because it defaults to 0 therefore it replaces itself. Auto is also set to 0 and is the default, metal is 0 ,gles3 is 1 and gles2 is 2.
Answer by Marcos-Elias · Jul 26, 2017 at 03:37 AM
I would love this also! I'm having serious troubles with my players because some features are not working in opengles 2 or 3, and vice-versa. It is hard keeping two versions of the game, I must create an option so the user may change it.
Answer by M_PLY · Feb 01, 2018 at 04:22 PM
I would like to know this as well. Is there any method to set the GraphicsDeviceType on runtime? Something like this?
private void SetGraphicsDevice()
{
UnityEditor.PlayerSettings.SetGraphicsAPIs(UnityEditor.BuildTarget.iOS,
new[] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2 });
}
Your answer
Follow this Question
Related Questions
Weird iPad render bug 0 Answers
Possible to render a simple colored spot rather than use a PNG? 0 Answers
Specifying a high quality background image for iPad 1 Answer
SpriteManager2 and Universal Apps 1 Answer
About iPhone/iPad development 1 Answer