How to set scripting define symbol in Editor?

I’ve tried setting them in Project Settings > Player > Other Settings > Scripting Define Symbols for PC, Mac & Linux Standalone, but this has no effect when running in Editor.

1 Like

Which version of Unity? MonoDevelop or Visual Studio?
You did it the correct way. Write them in there and hit enter. You might have to restart your IDE (I had such a bug in the past).

2 Likes

I’m using Unity v.5.3.2f1. I’m doing the defines in the Editor, not in the IDE (I use MonoDevelop mostly). When I run in Editor, they are not obeyed. Should I be setting them in MonoDevelop somehow? If so, how? Thanks for any help.

Well, I can only speak for Visual Studio, but if I define SOME_DEFINE in the editor (as you did), this works as expected:

#if SOME_DEFINE
    whatever();
#endif

Dumb question. But is your build target set to one of these platforms? These defines are platform specific.

Ah, duh! That’s it. I’m building for Android. I thought the Android player settings was only for the Android build, not also for the Editor (when the build is set to Android). Thanks!

All good. The editor will run define symbols for both the Editor and for the current build platform.

Thanks. This does beg the question for me: how do you set define symbols for the Editor per se, as opposed to for the current build platform?

Is there a reason the existing editor and platform defines don’t work for you?

Changing the Android settings works for both Editor and Android. I’m just confused by your reference to separate Editor defines, e.g. when you said “both the Editor and the current build platform”. I don’t see any Editor defines, just platform specific defines.

#if UNITY_EDITOR

#endif

That’s testing if you are running in Editor. That’s not what I’m asking. I’m asking how to have custom symbols when running in Editor. The answer is to define them in player settings for the current build platform. Case closed.

Except for @Kiwasi 's reference to define symbols for the Editor. There is no option in player settings for custom symbols for the Editor – only for specific platforms. So I’m just curious what he’s referring to there.

I believe he meant the UNITY_EDITOR definition; which is to say when you’re in the editor it is true along with whatever other symbols that are defined for the given platform selected in your build settings. Defining additional symbols only in the context of the Editor doesn’t really make sense since UNITY_EDITOR already tells you what environment you’re in. I think he was asking for use cases where that wouldn’t be sufficient.

1 Like

@Kelso – yeah I think you are right, there was a disconnect about what we were talking about.

I do think it would be nice to be able to define custom symbols for only the Editor (e.g. to turn on certain debugging messages temporarily), but it’s not a big deal, can set these using the current build platform, though need to remember to unset them before you build to that platform.

Totally agree. I’d love to have different levels of logging and the ability to turn logging to the console off as well as letting Unity just strip Debug.* calls out of the final build automatically.

Wow is there still no way to do this? because it’s pretty crucial. We want to be able to define Loggin for the editor build, but not the WebGL build, however since we only really build for WebGL we generally have the platform setting set to the WebGL platform. It makes no sense to make people set the define based on weather they are truly building for WebGL as opposed to the editor.
Did anyone come up with a good solution>

I mean, for what you’re trying to do you could literally just wrap your log calls in the UNITY_EDITOR symbol. Then it logs in the editor and not in the build.

#if UNITY_EDITOR
    Debug.Log("Hi, I only log & am compiled when in Unity Editor");
#endif

If you’re using custom defines, that you only want enabled when you build, you could use my script in Custom Define Manager Unity Asset Store - The Best Assets for Game Making to call CustomDefineManager.EnableDirective(“MyCustomWebGLDefine”); inside of a custom build script.
Unity - Manual: Build Player Pipeline

2 Likes

This works great for me:

[UpdateAfter(typeof(ExportPhysicsWorld))]
public class CameraFollowSystem : SystemBase
{
    private EntityCommandBufferSystem ecbSystem;
    protected override void OnCreate()
    {
        ecbSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
        base.OnCreate();
    }
    protected override void OnUpdate()
    {
        var ecb = ecbSystem.CreateCommandBuffer();
        Entities
            .WithoutBurst()
            .ForEach((Entity entity, ref Translation translation, in CameraFollow follow) =>
            {
                var targetPosition = EntityManager.GetComponentData<Translation>(follow.target).Value;
                translation.Value = targetPosition + follow.offset;
#if !HYBRID_ENTITIES_CAMERA_CONVERSION
                ecb.AddComponent<CopyTransformToGameObject>(entity);
#endif
            })
            .Run();
    }
}

Either using convert and inject, or setting HYBRID_ENTITIES_CAMERA_CONVERSION and convert and destroy