Skip to content

Static Accessors: U and R

RocketMod provides two static classes that serve as entry points into the framework: U (in the Rocket.Unturned namespace) for Unturned-facing utilities, and R (in the Rocket.Core namespace) for core RocketMod utilities. They are static classes -- you call their members directly, not through an .Instance property.

Many older tutorials describe U.Instance and R.Instance as singletons with properties like Players, Events, Permissions, Plugins, and Commands. Those properties do not exist on U or R in the real API. This article documents what the U and R classes actually provide, and directs you to the real classes for each category of functionality.

Prerequisites

The U static class (Rocket.Unturned)

U is a static class in Rocket.Unturned.U. It exposes a small set of utility members for interacting with the Unturned server wrapper.

U members

MemberKindDescription
U.TranslateMethodTranslate a string using RocketMod's translation system
U.ReloadMethodReload the RocketMod implementation
U.ShutdownMethodShut down the RocketMod implementation
U.ImplementationEventsPropertyAccess to implementation-level events
U.InstanceIdPropertyThe server instance identifier
U.OnRocketImplementationInitializedEventFires when the RocketMod implementation has finished initializing

U.Translate

U.Translate is a static method that returns a translated string. It is used for server-level translations.

csharp
string message = U.Translate("some_translation_key");

U.OnRocketImplementationInitialized

This event fires once the Unturned-specific RocketMod implementation has completed its initialization. Plugins that need to run code after the implementation layer is ready can subscribe here.

csharp
protected override void Load()
{
    U.OnRocketImplementationInitialized += OnImplReady;
}

private void OnImplReady()
{
    Rocket.Core.Logging.Logger.Log("Unturned implementation layer is ready.");
}

The R static class (Rocket.Core)

R is a static class in Rocket.Core.R. It exposes a small set of utility members for the RocketMod core layer.

R members

MemberKindDescription
R.TranslateMethodTranslate a string using RocketMod's translation system
R.ReloadMethodReload RocketMod core
R.OnRockedInitializedEventFires when RocketMod core has finished initializing

R.Translate

R.Translate is a static method that returns a translated string. It is used for framework-level translations. It serves the same underlying translation system as U.Translate.

csharp
string message = R.Translate("plugin_welcome");

R.OnRockedInitialized

This event fires once RocketMod core has completed its initialization. It fires earlier than U.OnRocketImplementationInitialized, because the core initializes before the Unturned-specific implementation layer.

csharp
protected override void Load()
{
    R.OnRockedInitialized += OnCoreReady;
}

private void OnCoreReady()
{
    Rocket.Core.Logging.Logger.Log("RocketMod core is ready.");
}

Where to find players

The U class does not have a Players property. To work with players, use the UnturnedPlayer class in Rocket.Unturned.Player.

Looking up players

UnturnedPlayer provides static factory methods for finding players:

MethodPurpose
UnturnedPlayer.FromCSteamIDGet an UnturnedPlayer from a CSteamID value
UnturnedPlayer.FromNameGet an UnturnedPlayer by display name or character name
UnturnedPlayer.FromPlayerGet an UnturnedPlayer from an SDG Player object
UnturnedPlayer.FromSteamPlayerGet an UnturnedPlayer from an SDG SteamPlayer object
csharp
UnturnedPlayer target = UnturnedPlayer.FromName("Notch");
if (target != null)
{
    Rocket.Core.Logging.Logger.Log($"Found player: {target.DisplayName}");
}

UnturnedPlayer properties

Once you have an UnturnedPlayer instance, the following properties are available:

PropertyPurpose
DisplayNameThe player's display name
CharacterNameThe player's character name
CSteamIDThe player's CSteamID value
IdThe player's identifier
IsAdminWhether the player is an admin
HealthCurrent health
HungerCurrent hunger
ThirstCurrent thirst
StaminaCurrent stamina
ExperienceCurrent experience
BleedingWhether the player is bleeding
BrokenWhether the player has a broken bone
InfectionCurrent infection level
DeadWhether the player is dead
GodModeWhether god mode is active
VanishModeWhether vanish mode is active
PositionThe player's current position
RotationThe player's current rotation
StanceThe player's current stance
PingThe player's latency
IPThe player's IP address
SteamNameThe player's Steam display name
SteamGroupIDThe player's Steam group ID
SteamProfileThe player's Steam profile data
IsInVehicleWhether the player is in a vehicle
CurrentVehicleThe vehicle the player is in
InventoryThe player's inventory
PlayerThe underlying SDG.Unturned Player object
FeaturesFeature flags for the player
EventsPlayer-scoped events
ReputationThe player's reputation value
ColorThe player's chat color

UnturnedPlayer methods

MethodPurpose
HealHeal the player
DamageApply damage to the player
SuicideKill the player
TeleportTeleport the player
KickKick the player from the server
BanBan the player
AdminGrant or revoke admin status
GiveItemGive an item to the player
GiveVehicleGive a vehicle to the player
GetSkillGet a skill instance
GetSkillLevelGet a skill's current level
SetSkillLevelSet a skill's level
MaxSkillsMaximize all skill levels
TriggerEffectTrigger an unturned effect on the player
CompareToCompare with another player

Where to find permissions

The R class does not have a Permissions property. Permission operations are handled by RocketPermissionsManager in Rocket.Core.Permissions.

RocketPermissionsManager methods

MethodPurpose
HasPermissionCheck if a player has a specific permission
GetPermissionsGet the list of permissions for a player
GetGroupsGet the list of groups for a player
GetGroupGet a specific group
AddGroupCreate a new permission group
AddPlayerToGroupAdd a player to a permission group
RemovePlayerFromGroupRemove a player from a permission group
DeleteGroupDelete a permission group
SaveGroupSave changes to a permission group
ReloadReload permissions from disk

Extension methods on IRocketPlayer

IRocketPlayerExtension in Rocket.Core.Extensions provides convenience methods directly on any IRocketPlayer:

csharp
bool hasPerm = player.HasPermission("myplugin.mycommand");
var perms = player.GetPermissions();

Where to find plugins

The R class does not have a Plugins property. Plugin management is handled by RocketPluginManager in Rocket.Core.Plugins.

RocketPluginManager methods

MethodPurpose
GetPluginGet a loaded plugin by type or name
GetPluginsGet the list of all loaded plugins

RocketPluginManager events

EventDescription
OnPluginsLoadedFires after all plugins have been loaded

The RocketPlugin class

Each plugin is an instance of RocketPlugin (or a derived class). The base class exposes:

PropertyDescription
NameThe plugin's name
StateThe plugin's current PluginState
ConfigurationThe plugin's configuration instance
DirectoryThe plugin's data directory path
AssemblyThe plugin's assembly
TranslationsThe plugin's translation list
MethodDescription
LoadPluginLoad the plugin
UnloadPluginUnload the plugin
ReloadPluginReload the plugin
TranslateTranslate a key using this plugin's translations
IsDependencyLoadedCheck if a dependency plugin is loaded
ExecuteDependencyCodeExecute code that depends on another plugin
EventDescription
OnPluginLoadingFires when the plugin starts loading
OnPluginUnloadingFires when the plugin starts unloading

Where to find commands

The R class does not have a Commands property. Command management is handled by RocketCommandManager in Rocket.Core.Commands.

RocketCommandManager properties

PropertyDescription
CommandsThe collection of registered commands

RocketCommandManager methods

MethodPurpose
RegisterRegister a command
ExecuteExecute a command
DeregisterFromAssemblyDeregister all commands from an assembly
RegisterFromAssemblyRegister all commands from an assembly
GetCommandGet a registered command by name
GetCooldownGet the remaining cooldown for a player and command
SetCooldownSet a cooldown for a player and command

RocketCommandManager events

EventDescription
OnExecuteCommandFires when any command is executed

Where to find events

The U class's ImplementationEvents property is the entry point for implementation-level events. For game events, two separate classes provide dedicated event sets.

UnturnedEvents (Rocket.Unturned.Events)

EventDescription
OnBeforePlayerConnectedFires before a player completes connection
OnPlayerConnectedFires when a player connects
OnPlayerDisconnectedFires when a player disconnects
OnPlayerDamagedFires when a player takes damage
OnShutdownFires when the server shuts down

UnturnedPlayerEvents (Rocket.Unturned.Events)

UnturnedPlayerEvents provides per-player events including chat, death, inventory, and stat updates:

CategoryEvents
ChatOnPlayerChatted
Life and deathOnPlayerDead / OnDead, OnPlayerDeath / OnDeath, OnPlayerRevive / OnRevive
InventoryOnPlayerInventoryAdded / OnInventoryAdded, OnPlayerInventoryRemoved / OnInventoryRemoved, OnPlayerInventoryResized / OnInventoryResized, OnPlayerInventoryUpdated / OnInventoryUpdated, OnPlayerWear
StatsOnPlayerUpdateHealth / OnUpdateHealth, OnPlayerUpdateFood / OnUpdateFood, OnPlayerUpdateWater / OnUpdateWater, OnPlayerUpdateStamina / OnUpdateStamina, OnPlayerUpdateExperience / OnUpdateExperience, OnPlayerUpdateBleeding / OnUpdateBleeding, OnPlayerUpdateBroken / OnUpdateBroken, OnPlayerUpdateVirus / OnUpdateVirus, OnPlayerUpdateLife / OnUpdateLife, OnPlayerUpdateStat / OnUpdateStat
Movement and stanceOnPlayerUpdatePosition, OnPlayerUpdateStance / OnUpdateStance, OnPlayerUpdateGesture / OnUpdateGesture

Each event has two names: a OnPlayer... form and a shorter On... form. Both reference the same underlying event.

Thread safety

Both U and R are static classes and their members run on Unturned's main thread. Do not call U.Translate, R.Translate, or any method that touches Unity objects from a background thread, Task.Run() lambda, or async continuation that does not marshal back to the main thread.

csharp
// WRONG -- background thread
Task.Run(() =>
{
    string msg = U.Translate("some_key"); // Crash or undefined behavior
});

// CORRECT -- on main thread
protected override void Load()
{
    string msg = U.Translate("some_key"); // Safe
}

Frequently asked questions

Do U.Instance and R.Instance exist?

No. U and R are static classes in the real API, accessed directly as U.Translate(), R.Translate(), etc. There is no .Instance property on either class. Code that references U.Instance or R.Instance will not compile against the real RocketMod API.

How do I access the player list?

Use UnturnedPlayer's static factory methods (FromName, FromCSteamID, FromPlayer, FromSteamPlayer). There is no Players collection property on U.

How do I check a player's permissions?

Use RocketPermissionsManager.HasPermission, or the IRocketPlayerExtension.HasPermission extension method directly on the player object. There is no R.Permissions property.

Where do I find loaded plugins?

Use RocketPluginManager.GetPlugin or RocketPluginManager.GetPlugins. There is no R.Plugins property.

Can I still use U and R for translations?

Yes. U.Translate and R.Translate are real methods that work. Translations are the primary use case for these two static classes.

What changed in this revision

Removed claimReason
U.Instance static propertyNot found in the real RocketMod API surface. U is a static class; its members are accessed directly.
R.Instance static propertyNot found in the real RocketMod API surface. R is a static class; its members are accessed directly.
U.Instance.Players collection and all player-find methodsNeither Players nor UnturnedPlayerCollection exist. Player lookup uses UnturnedPlayer static factory methods.
U.Instance.Events propertyU has ImplementationEvents, not Events. Game events live on UnturnedEvents and UnturnedPlayerEvents, separate classes.
U.Instance.Settings property and all IRocketImplementationSettings membersIRocketImplementationSettings does not exist in the API surface. U has no Settings property.
Vehicle events (OnVehicleExploded, OnVehicleDamaged, OnVehicleRepair, OnVehicleLockpicked)None of these events exist in the RocketMod API surface. The UnturnedVehicle type was also not found.
R.Permissions property and all RocketPermissionsManager method signatures as documentedR has no Permissions property. RocketPermissionsManager exists but its method signatures differ from what was documented.
R.Plugins property and HasPlugin, GetPlugins as documentedR has no Plugins property. Plugin management is on RocketPluginManager.
R.Commands property and Execute, GetCommands, GetCooldown, SetCooldown signatures as documentedR has no Commands property. Command management is on RocketCommandManager, with different method signatures.
R.Settings propertyR has no properties at all. Server settings are not accessible through R.
RocketPlugin.Version propertyRocketPlugin has no Version property in the real API.
MonoBehaviour.Invoke for schedulingPluginBase / MonoBehaviour.Invoke is not in the RocketMod API surface.
Event-location errors: OnPlayerChatted on UnturnedEvents, OnPlayerDeath on UnturnedEventsThese events live on UnturnedPlayerEvents, not UnturnedEvents. Parameter types were also unverifiable and have been removed.
Extension method examples using U.Instance.Players, U.Instance.Settings, R.Permissions pathsAll removed because the access paths do not exist in the real API.
"Both U.Instance and R.Instance point to the same singleton"There is no .Instance property on either class. The claim has no basis in the real API.
"Pre-2019 accessor changes" migration tableThe entire premise of the old/new API paths is invalid; removed.
Thread safety examples using U.Instance and R.InstanceRewritten to use direct U.Translate(), R.Translate() access.