Skip to content

Your first mod ​

Build a floor-mounted part named Simple Part with a custom model, collider, and mount socket. You can find it in the game's StellarWorks tab and build it for one Iron.

Create the project ​

Create a MyFirstMod folder with the following files. Download simple_part.glb and save it in Assets/models.

text
MyFirstMod/
  Assets/models/simple_part.glb
  Local.props
  MyFirstMod.csproj
  Mod.cs

Use this MyFirstMod.csproj.

xml
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <LangVersion>latest</LangVersion>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <Import Project="Local.props" Condition="Exists('Local.props')" />

  <PropertyGroup>
    <ManagedPath Condition="'$(ManagedPath)' == ''">$(GamePath)/StellarDrive_Data/Managed</ManagedPath>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="stellarworks" Version="1.0.0" ExcludeAssets="runtime" />
    <PackageDownload Include="LavaGang.MelonLoader" Version="[0.7.3]" />
    <Reference Include="MelonLoader" HintPath="$(NuGetPackageRoot)lavagang.melonloader/0.7.3/lib/net35/MelonLoader.dll" Private="false" />
    <Reference Include="UnityEngine.CoreModule" HintPath="$(ManagedPath)/UnityEngine.CoreModule.dll" Private="false" />
    <EmbeddedResource Include="Assets/models/simple_part.glb" LogicalName="StellarWorks.Assets/models/simple_part.glb" />
  </ItemGroup>

  <Target Name="ValidateReferences" BeforeTargets="ResolveAssemblyReferences">
    <Error Condition="!Exists('$(ManagedPath)/UnityEngine.CoreModule.dll')" Text="Set GamePath to your game installation." />
  </Target>
</Project>

Set GamePath in Local.props to your game folder. Keep this machine-specific file out of source control. If needed, set ManagedPath to override the path derived from GamePath.

xml
<Project>
  <PropertyGroup>
    <GamePath>C:/Program Files (x86)/Steam/steamapps/common/StellarDrive Demo</GamePath>
  </PropertyGroup>
</Project>

Register the part ​

Create Mod.cs and register the part during OnInitializeMelon. The loader dependency makes StellarWorks initialise before your plugin.

csharp
using System.Numerics;
using MelonLoader;
using StellarWorks.API;
using StellarWorks.Parts;

[assembly: MelonInfo(typeof(MyFirstMod.Mod), "My First Mod", "1.0.0", "YourName")]
[assembly: MelonGame("CuriousOwlGames", "StellarDrive")]
[assembly: MelonAdditionalDependencies("StellarWorks")]

namespace MyFirstMod
{
    public sealed class Mod : MelonMod
    {
        public override void OnInitializeMelon()
        {
            var mod = StellarWorksApi.RegisterMod("example.firstmod", typeof(Mod).Assembly);

            var part = mod.Parts.Create("simple_part")
                .WithName("Simple Part")
                .WithModel("models/simple_part.glb")
                .WithSize(new Vector3(0.8f))
                .WithMass(100f)
                .WithPlacement(PlacementSurface.Floor, "bottom")
                .WithCollider(new BoxColliderDefinition(new Vector3(0.8f), Vector3.Zero))
                .WithSocket(new SocketDefinition("bottom", SocketKind.Structural, new Vector3(0, -0.4f, 0)))
                .WithCost(Item.Native.Iron, 1);

            part.Register();
        }
    }
}

The assembly argument tells StellarWorks where to find the embedded model. The registered part's stable key is example.firstmod:simple_part. Keep that key when updating a released mod so previously saved parts resolve.

Continue to Build and install. Once the part works in game, add research and other content or a gameplay component.

StellarWorks documentation · Mods for StellarDrive