Skip to main content

Excluding C# code from compilation process

A playable ads is a short representation of a part of the game; using Luna you can easily take your game an Unity and isolate the features you would like to showcase in the ad experience.

When doing this, you may find that parts of your code are no longer required or necessary for the playable experience, and so they should be removed from the compilation process.

To do this, you can either exclude and entire script (code excludes) or parts of a script (block excludes).

Code Excludes

It may be the case when the original, fully-featured game relies on the APIs that are not available in Luna, but the availability of those APIs is not a hard requirement for a playable. For instance, the full version of the game might use Unity's AI system with C# scripts communicating to this system, and the playable creative slice can be easily done without that behaviour.

That is the reason Luna UI features an ability to exclude certain folders and files from compilation process as initiated by the developer.

How to configure code excludes

Luna has a separate tab in the Code section named Exclusions, which is dedicated to this particular purpose:


Excluding a set of files or an individual file from compilation by Luna is as easy as ticking a checkbox next to a folder or a C# file. This action doesn't alter the Unity project in any way and simply removes the corresponding files from Luna solution.

It is a very effective way of quickly reducing the number of build errors if the app relies heavily on third-party libraries (Social SDKs, Ad SDKs and so on).

Make sure to exclude files carefully. Removing scripts that are used in the scene or added to the objects dynamically will not lead to compilation errors but would potentially crash the app in runtime!

C# Block Excludes

Sometimes the logic within existing C# files is crucial for the game to work, but at the same time is heavily interweaved with logic related to things that are unsupported in Luna. This can range from a missing API to (much more likely) third-party libraries' integration. For instance, a C# script responsible for core game logic might contain invocations of an Analytics service.

For this particular matter, Luna provides a C# define helping to guard blocks of code when those are compiled by Luna.

How to configure code block excludes

Similarly to UNITY_EDITOR define and the like, Luna sets up it's own define, UNITY_LUNA. This way, a developer can wrap a block of code using a conditional preprocessor directive to avoid some path of the code from being compiled:


This define is also enabled in Luna's VS solution, thus hinting to the developer that particular blocks of code will (or will not) take part in compilation process.

The UNITY_LUNA define can also be used to invoke bits of code only in Luna, shall this necessity appear. Although in most cases it is considered a better practice to drive such things using settings of game objects / store flags in a scriptable object / configure via an external file, it might become handy to quickly adjust some parts for Luna only (i.e. load level number 5 instead of 1 if the game is built with Luna).