Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Problem with '#if UNITY_URP'

Discussion in 'Scripting' started by jma00049, Jun 28, 2021.

  1. jma00049

    jma00049

    Joined:
    Feb 21, 2019
    Posts:
    89
    Hello, I have an URP project and I have duplicated a SteamVR script to do some modifications to it to work as I needed (I removed namespace and changed some class calls). My problem now is that one part of the code has stopped working:
    Code (CSharp):
    1. #if UNITY_URP
    2.         tintColorId = Shader.PropertyToID( "_BaseColor" );
    3. #else
    4.         tintColorId = Shader.PropertyToID("_TintColor");
    5. #endif
    As I have an URP project, the first part of the if should be executed but it doesn't. The else is beeing executed and it throws me an error: "Material 'URPTeleportAreaVisible' with Shader 'Universal Render Pipeline/Particles/Unlit' doesn't have a color property '_TintColor'"
    Also, in my code, the first part of the if is like commented (gray color)

    Anyone knows what can be happening? Thanks!
     
  2. Q-Ted

    Q-Ted

    Joined:
    Dec 16, 2016
    Posts:
    46
    UNITY_URP is not something Unity adds to the define constraints when you include the Universal RP package. The SteamVR Unity Plugin team over at Valve added it to the assembly definition file for their plugin.

    https://github.com/ValveSoftware/steamvr_unity_plugin/blob/master/Assets/SteamVR/SteamVR.asmdef

    In the versionDefines section you can see that if the "com.unity.render-pipelines.universal" resource is available that "UNITY_URP" gets defined within the assembly. If your project won't change from being a URP project getting rid of the non-URP code and the define check should be good. Or, you can define it yourself in the Scripting Define Symbols in the Player Settings of your project.
     
    jma00049 likes this.
  3. jma00049

    jma00049

    Joined:
    Feb 21, 2019
    Posts:
    89
    Perfect! Thank you for the solution. I didn't know that was included by Valve in their plugin. My project is always URP so I will delete the check.