Passing Defines to Packages

I’ve read this old thread but I didn’t want to resurrect it.

I have some packages that make use of #if/#else. E.g. I have logging functionalities that can be disabled for release builds. Right now the suggested way to have optional features is to gather and separate the code in an asmdef with a define constraint. Unity - Manual: Assembly Definitions This would make things very ugly and unmaintainable.

In order to keep my code working I can make use of the Version Defines feature. The only way I have to define something in a package is via another package being installed. Unity - Manual: Assembly definitions . I can create empty packages that other packages use to trigger defines. This is very hacky and dirty, and makes the defines management ugly for the devs. Also controlling the defines via code would mean to install/uninstall packages, and it’s slow.

Also, having multiple assemblies makes impossible to have partial classes split between them.

Would be possible to gain access to the defines for the packages? I think the best solution would be to write in the asmdef which are the defines used by the assembly, so that it can be not recompiled on random defines changes.

Hello!

These versionDefines aren’t meant as arbitrary feature toggles, they are meant for automatically turning on/off code based on optional dependencies being present. Package authors can still use whatever custom defines they want, and either instruct users to manually add/remove project defines, or do so programmatically: Unity - Scripting API: PlayerSettings.SetScriptingDefineSymbolsForGroup

The Package Manager currently doesn’t have a way to dynamically define asmdef which defines the overrides. Unfortunately PlayerSettings.SetScriptingDefineSymbolsForGroup will affect the whole project, when what they really want is a similar feature but for their package/asmdef specifically. That’s a feature request for the Compilation Pipeline