Call another mod's API
Add the API to your project, mark the mod optional, and call it. The “Use this API” block on each API reference page has the exact file and csproj lines.
Pick your kind of API
Section titled “Pick your kind of API”| Kind | Mods | What you add |
|---|---|---|
| One source file | Snitch, Hotline, Sideload, TightBeam, Clipwise, Hash | Copy one .cs file into your project. Nothing extra to ship. |
| The mod’s DLL | SideHustle, Personnel, Inkorporated | Reference the mod’s DLL with <Private>false</Private>. |
Steps for a source file
Section titled “Steps for a source file”-
Copy the file into your project:
<Compile Include="path\to\Snitch.cs" /> -
Mark the mod optional:
[assembly: MelonOptionalDependencies("Snitch")] -
Call it. Without the mod, every call does nothing and returns a default.
using Snitch.Api;using (Profiler.Sample("MyMod.Pathfinding")){// runs the same with or without Snitch}
Calls made before the mod loads run when it loads. Load order does not matter.
Steps for a DLL
Section titled “Steps for a DLL”-
Reference the DLL from your game’s
Modsfolder:<Reference Include="SideHustle"><HintPath>path\to\Schedule I\Mods\SideHustle.dll</HintPath><Private>false</Private></Reference> -
Mark the mod optional, as above.
-
Put every call into a separate class, and call that class only when the mod is loaded.
A method that names a type from a missing DLL fails before its first line. A
try/catchinside that method does not catch it. SideHustle shipsSideHustleLink.csfor this.
Rules for every API
Section titled “Rules for every API”-
Call the API from Unity’s main thread. Your callbacks also run on the main thread.
-
In a hot path, check the API’s
EnabledorAvailableflag first. A call that does nothing still costs a call.if (Profiler.Enabled){using (Profiler.Sample("MyMod.Inner")) { }}
Support an older version of the mod
Section titled “Support an older version of the mod”The reference shows the latest release. A member that came later says Added in x.y.z. A member without that line exists in every release.
The Changes by version page lists what each release added and removed. Read “Removed” before you raise the version you require.