OnServerInitialize
OnServerInitialize is called by ServerMgr.Initialize before the server creates its persistence layer and player state manager, so it runs at the very start of a server boot before any save data is loaded.
void OnServerInitialize()Return value
The return value is ignored. Returning a value or null from OnServerInitialize has no effect on ServerMgr.Initialize or the rest of the boot sequence.
How it works
The hook fires once per server start, injected at the top of ServerMgr.Initialize. Because it runs before UserPersistance and PlayerStateManager are constructed, nothing about players, saves or entities can be relied on yet; the world and player states do not exist. There are no parameters. Common uses are one-time setup that must happen before save loading: writing a default data file, adjusting ConVar values so they are in place when the save is read, or recording a boot timestamp. Oxide plugins are already loaded when this fires, but OnServerInitialized has not run yet and entity hooks have not fired. Note that the hook returns nothing useful: the method's return value is ignored, so it cannot change whether initialization succeeds. If you only need to touch entities or players, use OnServerInitialized instead, which runs after the world and player state are ready. Keep work here short and side-effect free beyond configuration and data preparation.
Example plugin: Boot marker and pre-load config guard
using System;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Server Boot Marker", "RustPluginGenerator", "1.0.0")]
[Description("Records a boot marker during early server initialization and confirms readiness later")]
public class ServerBootMarker : RustPlugin
{
private const string DataFileName = "ServerBootMarker";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Boot tag")]
public string BootTag = "default";
[JsonProperty("Log readiness message")]
public bool LogReadiness = true;
}
private class BootRecord
{
[JsonProperty("Boot tag")]
public string Tag;
[JsonProperty("Boot UTC")]
public string BootUtc;
}
protected override void LoadDefaultConfig() => config = new PluginConfig();
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<PluginConfig>();
if (config == null) throw new Exception();
}
catch
{
PrintWarning("Configuration file is invalid, using defaults");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void SaveConfig() => Config.WriteObject(config);
private void OnServerInitialize()
{
var record = new BootRecord
{
Tag = config?.BootTag ?? "default",
BootUtc = DateTime.UtcNow.ToString("o")
};
Interface.Oxide.DataFileSystem.WriteObject(DataFileName, record);
}
private void OnServerInitialized()
{
if (config == null || !config.LogReadiness) return;
Puts($"Server boot ready (tag '{config.BootTag}') at {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss} UTC");
}
}
}The plugin records a boot marker during OnServerInitialize so admins have a timestamp of when the server began initializing, before any save data was read. It also enforces a configurable server identity hint by writing a small data file under oxide/data that other plugins can read. On OnServerInitialized it confirms the boot finished and logs the elapsed readiness path to chat/admin console. Configuration holds the boot tag and a toggle; LoadDefaultConfig provides sane defaults, and Unload saves nothing extra. The split between the two hooks shows the intended boundary: OnServerInitialize prepares data, OnServerInitialized acts on a ready world.
Common use cases
Stamp a boot time before save load
Write the current UTC time to a data file in OnServerInitialize so operators can see exactly when the process started initializing, independent of the world save.
Set convars before the save is read
Apply ConVar values that must be effective while the world loads, rather than after OnServerInitialized when the save has already been read.
Prepare a shared data file
Create or reset a data file that other plugins expect to exist on first boot, avoiding null reads later in OnServerInitialized.
Pitfalls
World and players do not exist yet
Do not query BasePlayer.activePlayerList, entities, or the world here. The persistence and player state layers are constructed after this hook fires.
Returning a value does nothing
The injection ignores the return value of the original method, so you cannot abort or alter server initialization from this hook.
Avoid heavy work
Spawns, save reads and long loops here can corrupt or slow the boot. Keep the body to data and configuration preparation, and defer real work to OnServerInitialized.
Build a plugin with OnServerInitialize
Describe what should happen and get a compiled plugin that uses this hook.
Edit the prompt on the next screen. 2 free plugins a month, no card.
Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.
Build a plugin with OnServerInitialize
Generate