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

Question SOLVED - 'PlayerSettings' does not exist in the current context

Discussion in 'Unity Build Automation' started by j1mmie, Dec 3, 2022.

  1. j1mmie

    j1mmie

    Joined:
    Oct 31, 2013
    Posts:
    31
    Hello, I'm trying to run a Pre-Export script in Unity Cloud Build that modifies PlayerSettings. The guidance I've found online says to

    1. Wrap the function with pre-compiler directive `#if UNITY_CLOUD_BUILD`
    2. Place your script in an Editor folder

    I've done exactly that, but still get this error
    Code (CSharp):
    1. 8: [2022-12-03T07:56:04Z - Unity] Assets\Editor\CloudBuildHelper.cs(8,5): error CS0103: The name 'PlayerSettings' does not exist in the current context

    My CloudBuildHelper.cs file looks like this:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class CloudBuildHelper : MonoBehaviour {
    4. #if UNITY_CLOUD_BUILD
    5.   public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest) {
    6.     var buildNumber = "unknown";
    7.     manifest.TryGetValue("buildNumber", out buildNumber);
    8.     PlayerSettings.bundleVersion = string.Format("0.0.{0}", buildNumber);
    9.   }
    10. #endif
    11. }
    12.  

    I'm using Unity 2021.3.14f1 in Cloud Build.

    Does anyone have any ideas on what it could be?
     
    Last edited: Dec 3, 2022
  2. j1mmie

    j1mmie

    Joined:
    Oct 31, 2013
    Posts:
    31
    Ignore me - forgot the line `using UnityEditor;`, d'oh!