Do you have a mod which interfaces with another mod? Do you want that mod to function with or without that other mod? Do you want your mod to be an optional dependency for other mods?
Preprocessor Directives might help you out! While there is no official standard for preprocessor directives, the below code block is a script file which I have included in my mods to flag their presence.
/**
* AG0 H47Chinook Preprocessor Directives
*
* This file handles conditional compilation flags for optional mod dependencies.
* It's named with "!" prefix to ensure it's compiled before other scripts.
* Defines are only valid in the module they are defined in, thus this script is defined in Scripts/Game, so references in other modules will fail.
*
* For mod developers:
* - If your mod may interface with this one, but you don't have this mod as a dependency, wrap code which interfaces with this mod using:
*
* #ifdef AG0_H47Chinook
* owner.FindComponent(AG0_CMWS_CountermeasuresComponent)
* #endif
*
* This ensures that the code is compiled only when the flag is set. If it's not, which it won't be if this mod is not loaded,
* it will ignore that code as if it never existed.
*/
#define AG0_H47Chinook
From my understanding, and it is certainly not a fact, the cleanest way to make your mod interoperable with other mods is to define in your mod a script file which defines a preprocessor directive. A preprocessor directive is essentially a variable, an argument, or a rule which tells the compiler of your scripts whether or not to compile certain portions. A common pre-processor directive is seen below:
#ifdef WORKBENCH
Print("Run me when I am loaded in workbench!");
#endif
By using preprocessor directives, and having more mods define them, we can more easily create compatible systems without being forced to use dependency relationships. For example, with the Multifunction Display Framework, it should not be necessary to have WCS_Armament as a dependency as it may be used on vehicles that don’t have or need countermeasures. Thus - by using the ifdef directive, I can create code which will only run when that mod is loaded - assuming that mod defines a directive correctly.
It is recommended for your directive to follow established naming standards for scripts, and to keep it simple - you can use your mod name prefixed with your TAG for the file name and definition. As noted above, by prefixing script name with exclamation point, you ensure your directive is loaded prior to and compilation of other scripts which might be compiled after the directive otherwise.
if ("TAG_ModClass".ToType())
// that mod is loaded
You can use scripting to check if a mod is loaded using a “soft” class type check. While any scripts you create using that class will fail to compile and lead to crashes without pre-processor directives, you can use this to see if a given mod is loaded and modify your approach accordingly, such as changing a prefab to disable/replace a component with your own without having to make a dependency/compatibility mod.