Gameplay and components
Worlds and entities
mod.World.Current returns an IWorld while a session is open. Access the world on the game thread. It exposes Id, SessionId, Role, State, ships, players, resource networks, and IsResearched(ContentId).
IShip, IPart, IPlayer, and resource networks implement IGameEntity. Use EntityHandle for lookup during its session with FindShip, FindPart, FindPlayer, or WorldResources.FindNetwork. Check IsValid before reuse. Store a PersistentId when the entity provides one, or the ContentId for a content definition. ModWorld.FindNativePart(shipId, partId, role) resolves a custom part by a current native address.
Events
ModEvent<T>.Subscribe(id, callback, options) returns a disposable registration. The ID is local to your mod and event stream. Register and dispose it on the game thread. SubscriptionOptions has priority and lifetime. The default is RegistrationLifetime.Framework. Register World subscriptions with a current session.
| Accessor | Published events |
|---|---|
Events.World | Opening, Loaded, LoadFailed, BeforeSave, Saved, SaveFailed, Unloading, Unloaded. |
Events.Parts | Authority placement policy, placement, load, removal, and destruction. Observation and local interaction events have their own hooks. |
Events.Ships, Events.Players | Tracked and Untracked for observed game entities. |
Events.Research | Unlocked for a technology. |
Events.Resources | Resource changes and authority solver-step events. |
Inspect World.Role before using authority-only APIs in a handler. Placement policy runs synchronously before build costs and topology change. The first PlacementRequest.Cancel(reason) during dispatch wins. PlacementRejected reports that result.
Components
mod.Components.Register<T>(name, factory, options) returns the component type's ContentId. A factory receives a ComponentConfiguration and returns a fresh instance. Add the component by ID or by registered CLR type with PartBuilder.AddComponent. Options let you validate configuration, specify component dependencies or conflicts, and opt into ticking.
| Hook | Use |
|---|---|
OnInitialize | Set up the attached instance. |
OnPlaced, OnLoaded | Start active behaviour after a new placement or a load or observation. |
OnServerTick(float deltaTime) | Advance an authority component with Tick = true. |
OnClientTick(float deltaTime) | Advance a visual component with Tick = true. |
OnReplicatedStateChanged | Respond to new replicated state in a visual component. |
OnDestroyed, OnRemoved | React to destruction and clean up when the instance ends. |
PartContext exposes the part definition, identity, sockets, resources, authority flag, active state, and component lookup via GetComponent<T>(). VisualRoot belongs to visual instances. Inventory belongs to an authoritative part with native storage.
Use [Persist("key")] on a read/write property to include it in snapshots. Use [Replicate("key")] to send a readable authority property to visual components, which read it through PartContext.Replicated<T>(). Call MarkStateDirty() to signal a replication update. The default key is the property name. Keep keys stable or supply UpgradeState with a new SchemaVersion to transform a saved snapshot one version at a time. Component example