URP Package defines

Is there a define to check whether a project is using URP?

I modified a script found here to check the defines within the URP package but it looks like there are none

using UnityEditor;
using UnityEditor.Compilation;

public static class AssemblyLister {

    [MenuItem("Tools/List Player Assemblies in Console")]
    public static void PrintAssemblyNames() {
        UnityEngine.Debug.Log("== Player Assemblies ==");
        Assembly[] playerAssemblies =
            CompilationPipeline.GetAssemblies(AssembliesType.Player);

        foreach (var assembly in playerAssemblies) {
            UnityEngine.Debug.Log(assembly.name);
            string[] defines = assembly.defines;
            for (int i = 0; i < defines.Length; ++i) {
                UnityEngine.Debug.Log(defines[i]);
            }
           
        }
    }
}

You can use Version Defines in an Assembly Definition File to query this: Unity - Manual: Assembly definitions

This define will only be available in the Assembly Definition File that you set it up in.

Note that this only tells you whether URP is installed. To check whether it is actually in use, you can check whether GraphicsSettings.currentRenderPipeline is a UniversalRenderPipelineAsset instance: Unity - Scripting API: Rendering.GraphicsSettings.currentRenderPipeline

My issue is that I’m sharing a Unity package with 3rd parties, my package contains custom code required to handle URP projects.The checks can’t be done at runtime as the URP specific code will cause errors in non URP projects.

Based on my test code above, the URP package does not have any defines, or am I missing something?

My workaround for now is to create my own Scripting Define Symbol and ask users to add it to their project when using URP.

You can use Version Defines in your Assembly Definition File to setup defines for your assembly that gets turned on/off based on the version and availability of a package: Unity - Manual: Assembly definitions