Conditional compilation symbols

Two questions related to compilation symbols (sometimes called preprocessor directives):

(1) Where is there a list of symbols automatically defined, based on version/build/targets in the editor itself?

(2) Can I define my own scene/project-wide compilation symbols somewhere? (Ref. VS->Proj Options->Build->Conditional compilation symbols)

This page:

…mentioned two symbols, but can I just have a symbol saying whether it is Unity/Mono in the first place?

E.g. can I just say if Mono, if #UNITY?

  1. aside of the one mentioned on that page, the only other define I’m aware of is UNITY_IPHONE

  2. if then only in the py file that handles the whole compilation through the mono compiler

The code is always mono and always unity, so I don’t understand the last part

I wish to distinguish source builds within the Unity and Mono environments from the Microsoft C# Compiler.

Are there any symbols defined by Unity automatically, regardless of version?

Are there any symbols defined by Mono automatically, regardless of version?

I see the file compile_any.pl in Data\MonoCompiler.framework\compile_any.pl.

Can this be edited to add new directives? If so, how?

that differences don’t exist. you can’t build unity from MS C# compiler (VS can only be used as coding editor, not more).
You can build additional .net assemblies there and use your own compiler directives naturally but those don’t touch unity nor vice versa.

that differences don't exist. you can't build unity from MS C# compiler (VS can only be used as coding editor, not more).
You can build additional .net assemblies there and use your own compiler directives naturally but those don't touch unity nor vice versa.

There is definitely difference between targeting the Mono runtime and the MS runtime in builds. First of all, C# 3.0 does not work, so I cannot use extension methods, automatic properties, LINQ and some other things, second, many types are gone.

If you drop MS-built DLL:s into the Asset folder, they will target the Mono runtime, as type gets resolved on compilation. The consequence could be quite different.

I am already building multiple DLL assemblies using MS C# compiler and this runs 100% fine in Unity web/desktop builds. I build them in VS. I am keeping the Unity code editing within Unity/Scite to a minimum to remain productive. And I want to reuse source files in these assemblies in projects targeting ASP.NET, Compact Framework. This is already possible to do and I have done it. But I want to change the compiler directives “globally” for the Mono build, inside Unity, so that the Mono compiler can skip/include specific source lines.

Note that I am absolutely not trying to build the project/solution that is the “integration project” auto-generated by the Unity editor. This solution is (as understood) supported for IDE integration only. I have >10 VS projects which are standalone from the integration solution which then merges on the player build.

An example of what I wish to do is below. Since Unity is based on C# 2.0 we cannot use automatic properties, so the same property could be refactored as such, while still reusing the same source file. It is quite beautiful because it will eliminate a lot of very ugly copy-paste duplication for existing sources.

#if UNITY_BUILD

private String _name;
public String Name 
{
get { return _name; }
set { _name = value;
}

#else

public String Name { get; set; }

#endif

That way there naturally is a difference.
What I meant is that Unity always compiles with unity and does not care nor support MS .NET (which can become especially tricky if you are using stuff thats pure MS .NET only). At the time an additional hurdle is Mono 1.2.5 (which is primarily .NET 2.0 only with some higher stuff cut or only partially present which will become especially troublesome in web related stuff as you will likely find out)

Though independent of that I don’t see how a compiler directive relates to unity.
Its of importance for your solution that generates the unity usable .net assembly, but not for unity.

mono is used because they are loaded and executed within the mono environment, not within a MS .NET environment.

I’m pretty sure you could add own defines by adding them to the @defines array thats used for the compilation
the only case where anything related to compiler args etc was talked about in the past I think was in relation to the -unsafe flag

Thanks! I will check the @defines array you mentioned.

Does this array exist? Where can I find it? (I’m on Unity Pro 3.3, on Windows 7)

I also had the question and this page was the first result from DuckDuckGo search engine.

Here is the link to the docs for the conditional compilation symbols.

Knowing if there are defines relevant to this could be handy if you’re using shared code, though.

The docs in this link says there is a place where you can add custom defines but it’s not there in Unity 3.4.2 ( Windows 7 Pro 64Bit).