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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

UNITY_WEBGL pragma

Discussion in 'Editor & General Support' started by collenti, Jan 27, 2016.

  1. collenti

    collenti

    Joined:
    Feb 10, 2013
    Posts:
    3
    Hello,

    I am using 5.3.1 (Mac, 10.10.5) and anything targeted only at the UNITY_WEBGL platform nonetheless runs in the editor. So, with the following,both Debug.Logs are produced in the console when running from the editor.

    If I screen for some other platform, the editor properly ignores it.

    #if UNITY_WEBGL
    Debug.Log("Called from webgl");
    #else
    Debug.Log("Called from editor");
    #endif

    I should add that if I change the code to make the webgl pragma false, the editor ignores the call yet, of course, in a web browser, the call gets ignored too. It is as if !UNITY_WEBGL in the editor really gets interpreted as true yet false in the browser.

    #if !UNITY_WEBGL
    Debug.Log("Called from webgl");
    #else
    Debug.Log("Called from editor");
    #endif
     
    Last edited: Jan 27, 2016
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    While running in the editor, the define symbols for the selected platform are also defined.
    If you currently have WebGL selected, both UNITY_EDITOR and UNITY_WEBGL will be set when running in the editor.
     
  3. collenti

    collenti

    Joined:
    Feb 10, 2013
    Posts:
    3
    Didn't know that. Thanks.