Platform dependent compilation not working properly? Game view VS WebGL

Hello everybody,

I just wondered if it is possible to run some code only in the game view and other only in a built WebGL?
Sofar I thought PlatformDependentCompilation would do exactly that, but I get Logs for both cases in the game view, although it should be one or the other, right?

If I do run this:

    public void Awake() {
        #if UNITY_EDITOR
        source_local = true;
        Debug.Log("source_local = true");
        #endif

        #if UNITY_WEBGL
        source_local = false;
        Debug.Log("source_local = false");
        #endif
    }

Although I should only get the log from the #if UNITY_EDITOR I get in the game views console in Unity 2021.1.15f1 on Windows I get both logs:

source_local = true
UnityEngine.Debug:Log (object)

source_local = false
UnityEngine.Debug:Log (object)

Unity sets the platform symbols also in the editor for the active build target. E.g. if WebGL is your active build target, UNITY_WEBGL will also be defined in the editor.

If you want something to be compiled for only when not in the editor, you’d have to use e.g. #if !UNITY_EDITOR && UNITY_WEBGL.

1 Like

A great many thanks Adrian :slight_smile:
Although it seems counter intuitive that UNITY_WEBGL is true in the editor your approach works fine.