Skip to content

Models and placement ​

A custom part needs a renderable model and at least one explicit box collider. Use a .glb or self-contained .gltf with its buffers and textures embedded. A GLB is convenient for distributing the mod in a single DLL.

Choose how to ship assets ​

  • Embedded. Pass the assembly to StellarWorksApi.RegisterMod(id, assembly). Embed assets with the logical name StellarWorks.Assets/<relative-path>. The first-mod project shows the exact MSBuild entry.
  • Loose files. Call StellarWorksApi.RegisterMod(id) and put the files under Mods/StellarWorks/<mod-id>/. For example, WithModel("models/simple_part.glb") loads Mods/StellarWorks/example.firstmod/models/simple_part.glb in the tutorial mod.

Use the same relative path in WithModel for either layout. Keep forward slashes and preserve case. Icons use PNG or JPEG.

Place and connect a part ​

Set a part's size and colliders in metres. BoxColliderDefinition uses full box dimensions and a centre. Supply a GLB node name if the box is relative to that node. Use WithPlacement with Floor, Wall, Any, or Jigsaw and, where applicable, name a structural socket as the mount.

A cable socket adds a power, fluid, or signal connection. Give each cable socket on a part a distinct slot, starting at zero with no gaps. Structural sockets omit the slot. Before part.Register() in the first mod, add a socket like this.

csharp
part.WithSocket(new SocketDefinition("signal_out", SocketKind.Signal, new Vector3(0.4f, 0, 0), slot: 0)
{
    Label = "Signal output"
});

Attach a resource component to make the socket participate in the native network. WithSocketRelay("inlet", "outlet") connects two distinct same-kind fluid or power sockets within a part. WithNativeStorage() equips a part with the game's ten-slot chest inventory and storage interaction.

Snap parts together with jigsaw endpoints ​

Add a point to the part already in the world and a node to the incoming part. They join when their endpoint ContentId values match. Orient each frame with +Z outward and +Y up. Choose PlacementSurface.Jigsaw for the incoming definition and give it at least one node. The build tool cycles through matching nodes in declaration order. ForcedRollDegrees on a point fixes the allowed roll. ExtendChainOnAim lets the build tool follow a chain to its open endpoint.

Create additional visual models ​

A visual component can load a model with mod.Assets.LoadModelAsync(path). Retain the returned ModelLease while using the decoded model. Instantiate it through mod.Assets.InstantiateModel(lease, parent) on the game thread, using the part's VisualRoot if appropriate. Dispose the resulting UnityModelInstance on the game thread and release the lease when the visual is removed. Check that the part is still active when an asynchronous load completes. Parts and assets reference

StellarWorks documentation · Mods for StellarDrive