Documentation Help

Writing A Basic Plugin

Before You Begin

The plugin which we will guide you to create in this guide will only teach you how to interact with AnchorChain. This guide isn't about building mods, just loading one via AnchorChain. If you would like to learn how to build a mod, then we recommend looking to the Harmony documentation.

What Anchor Chain Requires

As of writing, there is no nuget package for an Anchor Chain plugin, so you'll have to do things the old-fashioned way. Thankfully, AC plugins are fairly simple. There are two things that define a plugin:

The ACPlugin attribute is how AnchorChain will find and identify your plugin. It should be applied to any classes that you want to be loaded as a plugin.


public class ACPlugin([NotNull] string guid, string name, string version, string[] before, string[] after)

Arguments

  • string guid

    AnchorChain's internal name for your plugin. We recommend that you use reverse domain notation for GUID. For modders, this usually comes in the form of your github.io url. For example, AnchorChain's GUID is io.github.seapower_modders.anchorchain.


  • string name

    The name of your plugin is completely arbitrary. AnchorChain will only use it in logging and error messages, and it will always be paired with the plugin's guid.


  • string version

    The version of your plugin. Must be in a format acceptable by System.Version. AnchorChain recommends that you adhere to the convention of SemVer.


  • string[] before

    An array of plugins that you want your plugin to always load before. Do not use this option without reason, as if AnchorChain detects a conflict between two mods both wanting to load first, it will abort loading all mods.

    The plugins in before should be identified by their GUIDs.


  • string[] after

    An array of plugins that you want your plugin to always load after. Do not use this option without reason, as if AnchorChain detects a conflict between two mods both wanting to load second, it will abort loading all mods.

    The plugins in after should be identified by their GUIDs.

IAnchorChainMod is a simple interface, only consisting of a single method.


public interface IAnchorChainMod { public void TriggerEntryPoint(); }

TriggerEntryPoint()

This is what AnchorChain will call to load your plugin. As such, it should contain all setup required for your plugin.

    Writing Your Plugin

    1. Create a new project in your preferred code editor.

    2. Import AnchorChain to your project. The dll that you should use is available on our releases page in dev.zip.

    3. Create your plugin's namespace. We recommend choosing a unique name to avoid collisions with other mods.


    4. Your file should be similar to the following:

      using AnchorChain; namespace NewPlugin;
    5. Create a class for your plugin. It should be annotated with ACPlugin and implement IAnchorChainMod.

    6. Add your guid, name, and version string to ACPlugin.

    7. Create the public void TriggerEntryPoint function.


    8. Now, your code should look something like this:

      using AnchorChain; namespace NewPlugin; [ACPlugin("io.github.your-url.new-plugin", "New Plugin", "0.1.0")] public class NewPlugin : IAnchorChainMod { public void TriggerEntryPoint() { } }
    9. All that's left is to add your mod's code to TriggerEntryPoint(). For this example, we'll just make it log a message to console using Unity's Debug.Log().

    Finally, we have our completed plugin.

    using AnchorChain; using UnityEngine; namespace NewPlugin; [ACPlugin("io.github.your-url.new-plugin", "New Plugin", "0.1.0")] public class NewPlugin : IAnchorChainMod { public void TriggerEntryPoint() { Debug.Log("Hello Anchor Chain!"); } }

    Load Your Plugin

    First, make sure that the Anchor Chain and its preloader are installed in your Sea Power directory. If that is not the case, follow the instructions here.

    Anchor Chain is made to make loading plugins easier for users. Unfortunately, that does not translate into an easier time for modders. You will need to build your plugin and manually move it into <Sea Power>/Sea Power_Data/StreamingAssets

    Once your plugin is in StreamingAssets, just boot the game as normal. Your plugin will load and log your debug message to <your user directory>/AppData/LocalLow/Triassic Games/Sea Power/Player.log.

    Congratulations, you've made and loaded an Anchor Chain plugin!

    Last modified: 24 January 2025