Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Missing / Inaccessible PlayerSettings values

Discussion in 'Editor & General Support' started by DAVcoHL, Feb 23, 2018.

  1. DAVcoHL

    DAVcoHL

    Joined:
    May 3, 2017
    Posts:
    15
    I was recently setting up an automatic build script for a project, but I have discovered that I cannot get/set certain PlayerSettings values via [Editor] code.

    I've been through the docs and I can't find a way to get at any of the following values via PlayerSettings, EditorUserBuildSettings, etc - perhaps I'm missing something? Can someone shed any light on this?

    Missing Values (For standalone builds):
    • Color Gamut For Mac
    • Static Batching
    • Dynamic Batching
    • Lightmap Encoding
    • [Mac App Store] Category
    • Disable HW Statistics
    • Active Input Handling
    • Prebake Collision Meshes
    • Keep Loaded Shaders Alive
    • Preloaded Assets
    • Vertex Compression
    playerSettings.png
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    You have to access PlayerSettings as a SerializedObject and find the properties you are looking for. Look at you "ProjectSettings/ProjectSettings.asset" file in text format to find all the property names you want to change.

    Here's an example to set static and dynamic batching:
    Calling playerSettingsSerializedObject.FindProperty("m_BuildTargetBatching") will get you an array of BuildTargets inside a SerializedProperty. You can get one BuildTarget as a SerializedProperty out of the array by calling GetArrayElementAtIndex(index) on the SerializedProperty representing the BuildTarget array. Each BuildTarget is an array of Batching properties, so you can search the array for a SerializedProperty with the name "m_StaticBatching" and set it to whatever value you choose.
     
  3. DAVcoHL

    DAVcoHL

    Joined:
    May 3, 2017
    Posts:
    15
    Hi Gambit-MSplitz, thanks for that - I didn't realise that ProjectSettings was accessible as a SerializedObject!

    For anyone else who is interested - you can grab the PlayerSettings SerializedObject quite easily:

    PlayerSettings playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>()[0];
    SerializedObject playerSettingsSo = new SerializedObject(playerSettings);