{"record":{"id":"353f891d2e94a7a8","repo":"Unity-Technologies/UnityCsReference","slug":"value-cannot-be-null-parameter-defines","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'defines')","messagePattern":"Value cannot be null\\. \\(Parameter 'defines'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/PlayerSettings.bindings.cs","lineNumber":1094,"sourceCode":"            GetScriptingDefineSymbolsInternal(buildTarget.TargetName);\n        public static void GetScriptingDefineSymbols(NamedBuildTarget buildTarget, out string[] defines) =>\n            defines = ScriptingDefinesHelper.ConvertScriptingDefineStringToArray(GetScriptingDefineSymbols(buildTarget));\n\n        // Set user-specified symbols for script compilation for the given build target group.\n        public static void SetScriptingDefineSymbols(NamedBuildTarget buildTarget, string defines)\n        {\n            if (!string.IsNullOrEmpty(defines))\n                defines = string.Join(\";\", ScriptingDefinesHelper.ConvertScriptingDefineStringToArray(defines));\n\n            BuildProfileContext.UpdateScriptingDefineSymbolsInActivePlayerSettingsOverride(buildTarget, defines);\n\n            SetScriptingDefineSymbolsInternal(buildTarget.TargetName, defines);\n        }\n\n        public static void SetScriptingDefineSymbols(NamedBuildTarget buildTarget, string[] defines)\n        {\n            if (defines == null)\n                throw new ArgumentNullException(nameof(defines));\n\n            SetScriptingDefineSymbols(buildTarget, ScriptingDefinesHelper.ConvertScriptingDefineArrayToString(defines));\n        }\n\n        [StaticAccessor(\"GetPlayerSettings().GetEditorOnlyForUpdate()\")]\n        [NativeMethod(\"SetUserScriptingDefineSymbols\", ThrowsException = true)]\n        private static extern void SetScriptingDefineSymbolsInternal(string buildTargetName, string defines);\n\n        [StaticAccessor(\"GetPlayerSettings().GetEditorOnly()\")]\n        [NativeMethod(\"GetAdditionalCompilerArguments\", ThrowsException = true)]\n        private static extern string[] GetAdditionalCompilerArgumentsInternal(string buildTargetName);\n        public static string[] GetAdditionalCompilerArguments(NamedBuildTarget buildTarget) =>\n            GetAdditionalCompilerArgumentsInternal(buildTarget.TargetName);\n\n        public static void SetAdditionalCompilerArguments(NamedBuildTarget buildTarget, string[] additionalCompilerArguments)\n        {\n            if (additionalCompilerArguments == null)\n                throw new ArgumentNullException(nameof(additionalCompilerArguments));","sourceCodeStart":1076,"sourceCodeEnd":1112,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/PlayerSettings.bindings.cs#L1076-L1112","documentation":"Thrown by PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget buildTarget, string[] defines) when the defines array is null. The method expects at minimum an empty array (to clear defines) — null is rejected because it ambiguously represents either 'no change' or 'clear all', and the API contract requires an explicit empty array for clearing.","triggerScenarios":"Calling SetScriptingDefineSymbols with a null string[] — e.g. when a deserialized or reflected value is null, or when a conditional code path skips array initialization. Passing an empty array (new string[0]) is valid and clears all defines.","commonSituations":"Editor scripts that conditionally build a defines array and pass null when the condition is unmet; deserialization of scripting define lists that are null; migrating from the string overload (which accepts null/empty) to the array overload.","solutions":["Pass an empty array instead of null to clear defines: SetScriptingDefineSymbols(target, Array.Empty<string>()).","Initialize the array before the conditional: var defines = Array.Empty<string>(); then populate conditionally.","Null-coalesce at the call site: SetScriptingDefineSymbols(target, defines ?? Array.Empty<string>())."],"exampleFix":"// before\nPlayerSettings.SetScriptingDefineSymbols(target, null);\n\n// after\nPlayerSettings.SetScriptingDefineSymbols(target, defines ?? Array.Empty<string>());","handlingStrategy":"validation","validationCode":"PlayerSettings.SetScriptingDefineSymbols(target, defines ?? Array.Empty<string>());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass Array.Empty<string>() instead of null to clear scripting defines.","Initialize define arrays before conditional code paths that might skip population.","Null-coalesce at the call site to guarantee a non-null array."],"tags":["unity-editor","player-settings","scripting-defines","null-reference","argument-validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}