global #define?

Supposedly there is a trick to make a global #define (preprocessor tag) by creating a special file in the root of your project. Would someone share the specifics? I am sick of having to put my #defines in every .cs file that uses it.

1 Like

There is no trick, you can’t make global defines on a per project base.

the only thing you could do are unity wide defines that apply everywhere and that requires a little “hack”

Dreamora, I believe you are mistaken. I have it on good authority (mikeD from prime31) there is a way to make a global #define and not have to put it at the top of every .cs file that uses it. I’ll see if he can share the details, but he’s on the road and wasn’t able to tell me right away.

There is one way and thats modifying the compiler control script.

But thats not per project but per unity install

That sucks :frowning: Add votes here http://feedback.unity3d.com/forums/15792-unity/suggestions/164425-editor-interface-for-listing-preprocessor-macros-

Correction! There is an apparently mostly unknown and undocumented feature. See this thread. Just tried and it works with C# too:

http://forum.unity3d.com/threads/71445-How-To-Set-Project-Wide-pragma-Directives-with-JavaScript

1 Like

good catch, thats indeed unknown, never heard of it at least

That’s really neat we were looking for a feature like that for ages.

I noticed there is a us.rsp listed at the link too, I’m curious what other options are available and how we can go about figuring them out.

Unfortunately, it seems that Monodevelop does not always notice these defines :frowning: Compilation seems to work as expected, but the source code isn’t highlighted correctly and document outline is suspect. Reverting to putting the #define in .cs files, in some case.

MonoDevelop has it’s own Define list, that you can add to. Unity handles it’s own compilation (hence why the MonoDevelop output is called irrelvant.dll). Just go to Project Options → Build → Compiler → Define Symbols and add it in. You’ll notice the Unity defines are already manually included there.

Thanks Ntero!

I put togeather a simple example project to illustrate how to pass the compiler arguments for another thread, and thought I’d repost it here.

You can download it here: http://www.slipstreamgame.com/shares/DefineExample.rar

974281–36098–$DefineExample.rar (128 KB)

We got tired of manually managing the smcs/gmcs files so we threw together a quick little editor script to handle it for us. Nothing fancy here, just a simple UI to add/remove defines and force a recompile. Its up on Github for those interested: P31UnityAddOns/Editor/GlobalDefinesWizard.cs at master · prime31/P31UnityAddOns · GitHub

2 Likes

Prime31. . . brilliant as always. Thanks for sharing that.

1 Like

Thanks from all 6 of the coders here at Kuato :slight_smile:

Yeah thanks Mike D. / Prime31 !

Thanks from coders at school zone :smile:

That’s awesome. Thanks!

If anyone is still looking at this, seems like Unity4 has a fix.

Also changes can be done via the PlayerSettings inspector

EDIT the format is DEFINE1;DEFINE2. Make sure you don’t repeat DEFINE1 multiple times because the Unity build process will get a duplicate key exception.

1 Like

chsu, indeed it does - all I use now is the defines in playerSettings! thanks for following up this thread. One note to anyone trying it: the player settings are per platform which is confusing the first time you set a define, then switch platforms.