About ServerPrefabs
Need a robust foundation for creating custom Rust entities and prefabs from your own plugins? ServerPrefabs is a powerful library plugin for Oxide/uMod and Carbon that lets plugin developers register custom server-side prefabs and entities, with support for custom networking, persistent save/load, built-in inventories, and runtime scaling.
What Is ServerPrefabs?
ServerPrefabs is not a standalone gameplay plugin — it’s a developer library.
It does nothing on its own. Instead, other plugins use its API to define, register, and manage their own custom prefabs and entities on the server. If you’re building advanced Rust systems with custom deployables, persistent world objects, or specialized networked entities, ServerPrefabs provides the core framework you need.
Core Features
-
Custom Server-Side Prefab Registration:
Create and register fully custom prefabs directly from your plugin. Once registered, they become usable and spawnable by the game. -
Custom Entity Component Support:
Attach your ownBaseEntity-derived component to a prefab and define custom entity logic exactly how your plugin needs it. -
Persistent Save / Load System:
Custom entity save data is written to:
oxide/data/ServerPrefabs/<prefab>.sav -
Custom Network Serialization:
Provide your own network save behavior so clients receive the exact entity state they need. -
Arbitrary Per-Entity Data Storage:
Implement stream-based save/load methods for custom entity state and plugin-specific data. -
Built-In Inventory Component:
UseEntityInventoryfor a built-in, network-replicated item container with configurable capacity and optional handler callbacks. -
Runtime Scaling Support:
UseScalerto persist and replicate transform scale for custom entities. -
Lightweight Stub Entities:
UseStubEntityfor lightweight, non-saving entities with RPC and save event hooks, plus a helper factory for cloning visuals and bounds from a base prefab. -
Per-Entity Behavior Flags:
Opt into special behaviors such as disabling disk saving or excluding entities from spawn command lists viaCustomFlags.
Public API
The main entry point is:
ServerPrefabs.For(plugin)
This returns a per-plugin context you can use to create and register prefabs.
Example usage:
var prefab = ServerPrefabs.For(this) .CreatePrefab("my_thing") .AddEntityComponent<MyEntity>(clientPrefabId) .Register();
This workflow allows a consumer plugin to:
- Create a custom prefab
-
Attach a custom
BaseEntitycomponent - Register it with the game
- Make it available for spawning and runtime use
Extension Interfaces
-
ICustomPrefab
CallsOnCustomPrefabRegistered()once the prefab is registered. -
ICustomEntity
CallsOnCustomEntityRegistered()when the custom entity is registered. -
ICustomEntity.SaveForNetwork
Lets you customize the network proto sent to clients. -
ICustomEntity.SaveData
AddsSave(Stream)andLoad(Stream)support for arbitrary per-entity data.
Entity Flags
Optional behaviors are controlled through the EntityFlags CustomFlags property on ICustomEntity.
By default, the value is EntityFlags.None, so you only override it when special behavior is needed. The property is named CustomFlags specifically to avoid colliding with BaseEntity.Flags.
Example:
class MyEntity : BaseEntity, ServerPrefabs.ICustomEntity { public void OnCustomEntityRegistered() { } public ServerPrefabs.EntityFlags CustomFlags => ServerPrefabs.EntityFlags.DisableSaving | ServerPrefabs.EntityFlags.NoSpawnCommand; }
Available flags:
-
EntityFlags.None
No special behavior. -
EntityFlags.DisableSaving
Excludes the entity from disk saving by settingenableSaving = false. -
EntityFlags.NoSpawnCommand
Prevents the entity from being added to the spawnable-entity command list.
Included Components
-
EntityInventory
A built-in, network-replicated item container. SetCapacityand optionally assign anEntityInventory.IHandlerwith callbacks such as:-
OnCreated -
OnInventoryDirty -
OnItemAddedOrRemoved -
ItemFilter
-
-
Scaler
Persists and replicates entity transform scale. -
StubEntity
A lightweight, non-saving entity withonRpcMessageandonSaveevents, plus aStubEntity.Create<T>(...)factory for cloning visuals and bounds from a base prefab.
Installation
-
Drop
ServerPrefabs.csinto:-
oxide/plugins/ -
or
carbon/plugins/
-
- The server will compile and load it automatically.
- On first load, a config file is generated.
-
Dependent plugins can reference it via:
-
[PluginReference] Plugin ServerPrefabs; - or the static API
-
Configuration
Configuration file:
oxide/config/ServerPrefabs.json
-
Allow outdated saves
Default:false
Allows loading.savfiles written by a different Rust save protocol version. -
Enable debug logging
Default:false
Enables verbose[ServerPrefabs] [DEBUG]log output for troubleshooting.
Safe Config Recovery:
If the config becomes invalid or unreadable, it is automatically backed up as ServerPrefabs.json.bak. A new default config is then generated, so a broken manual edit won’t silently destroy your settings.
Compatibility Notes
ServerPrefabs uses Harmony IL transpilers against Rust internals, specifically:
-
SaveRestore.Load -
SaveRestore.WriteEntities
Because these patches rely on specific internal instruction patterns, a Rust update can break compatibility.
After a force wipe or game update, check the server console during load for errors like:
-
Phase 1 failed! -
Phase 2 failed! -
Phase 3 failed! - or other patch-related errors
If those appear, the plugin likely needs to be updated to match the current Rust version.
Why Use ServerPrefabs?
- Create advanced custom entities directly from your plugin
- Add server-side prefabs with persistent save/load support
- Customize network behavior for non-standard entities
- Use built-in inventory and scaling systems instead of building your own
- Control save and spawn-list behavior with simple entity flags
- Perfect for framework plugins, deployables, machines, automation systems, and persistent world objects
ServerPrefabs is a core utility library for Rust plugin developers who want deeper control over custom entities and prefab-based systems.
One library. Custom prefabs. Persistent entities. A powerful base for advanced Rust modding.