Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

ShaderBuildSettings.ValidateDefines

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static bool ValidateDefines(string[] defines, out string msg);

Parameters

Parameter Description
defines The constant define array to validate.
msg The error message if validation errors occur.

Returns

bool True if the constant define data is valid, otherwise false.

Description

Validates the given array of constant defines.

This method checks that the define array does not contain multiple entries with the same identifier. It also runs data validation on each element individually.

using UnityEditor.Shaders;
using UnityEngine;


public class DefineValidationExample
{
    void ValidateDefines()
    {
        string[] defineArray = new string[] { "MAX_NUM_LIGHTS 8", "EPSILON 0.1f" };

        // Check if the define array is valid. This will catch both duplicates and invalid individual defines.
        string validationErrors;
        if (!ShaderBuildSettings.ValidateDefines(defineArray, out validationErrors))
        { 
            Debug.LogWarning(validationErrors);
        }
    }
}