Search Unity

How to set scripting define symbol in Editor?

Discussion in 'Scripting' started by Ghopper21, May 15, 2016.

  1. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    170
    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.
     
    Gauri_R likes this.
  2. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
    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).
     
    Gauri_R and Aaron_Chan like this.
  3. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    170
    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.
     
  4. TheSniperFan

    TheSniperFan

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

    Code (csharp):
    1. #if SOME_DEFINE
    2.     whatever();
    3. #endif
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Dumb question. But is your build target set to one of these platforms? These defines are platform specific.
     
  6. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    170
    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!
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    All good. The editor will run define symbols for both the Editor and for the current build platform.
     
  8. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    170
    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?
     
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Is there a reason the existing editor and platform defines don't work for you?
     
  10. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    170
    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.
     
  11. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Code (csharp):
    1.  
    2. #if UNITY_EDITOR
    3.  
    4. #endif
    5.  
     
  12. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    170
    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 @BoredMormon'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.
     
  13. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    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.
     
    phemyo-a likes this.
  14. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    170
    @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.
     
  15. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    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.
     
  16. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    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>
     
  17. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    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.
     
  18. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    652
    kaozgaia1 and KelsoMRK like this.
  19. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    This works great for me:

    Code (CSharp):
    1.  
    2. [UpdateAfter(typeof(ExportPhysicsWorld))]
    3. public class CameraFollowSystem : SystemBase
    4. {
    5.     private EntityCommandBufferSystem ecbSystem;
    6.     protected override void OnCreate()
    7.     {
    8.         ecbSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
    9.         base.OnCreate();
    10.     }
    11.     protected override void OnUpdate()
    12.     {
    13.         var ecb = ecbSystem.CreateCommandBuffer();
    14.         Entities
    15.             .WithoutBurst()
    16.             .ForEach((Entity entity, ref Translation translation, in CameraFollow follow) =>
    17.             {
    18.                 var targetPosition = EntityManager.GetComponentData<Translation>(follow.target).Value;
    19.                 translation.Value = targetPosition + follow.offset;
    20. #if !HYBRID_ENTITIES_CAMERA_CONVERSION
    21.                 ecb.AddComponent<CopyTransformToGameObject>(entity);
    22. #endif
    23.             })
    24.             .Run();
    25.     }
    26. }
    27.  
    Either using convert and inject, or setting HYBRID_ENTITIES_CAMERA_CONVERSION and convert and destroy