codeAPI Reference
s&box UndoSystem: Per-player undo stacks
GameObjectSystem that provides per-player undo stacks with 128-step limit. Tracks GameObjects for destruction on undo.
Classes
PlayerStack
Per-player undo stack with bounded history.CSHARP
public class PlayerStack
{
/// Create a new undo entry.
public Entry Create()
/// Run the undo (destroys tracked GameObjects).
public void Undo()
/// Remove a GameObject from all entries in this stack.
public void Remove( GameObject go )
}Entry
Single undo action tracking GameObjects to destroy.CSHARP
public class Entry
{
/// Display name (format: "Undo something").
public string Name { get; set; }
/// Icon for UI display.
public string Icon { get; set; }
/// Add a GameObject to destroy on undo.
public void Add( GameObject go )
/// Add multiple GameObjects to destroy on undo.
public void Add( params IEnumerable<GameObject> gos )
/// Remove a GameObject from this entry.
public void Remove( GameObject go )
/// Run this undo (broadcasts notice to player).
public bool Run( bool sendNotice = true )
}Methods
CSHARP
/// Get the undo stack for a specific SteamId.
public PlayerStack For( long steamId )
/// Call when a player disconnects to prevent memory leaks.
public void RemovePlayer( long steamId )
/// Remove a GameObject from all player undo stacks.
public void Remove( GameObject go )Usage
Use UndoSystem.Current.For( steamId ).Create() to create an undo entry, then call Add() to track GameObjects. The system automatically limits history to 128 entries per player.
Example: After spawning a prop, create an undo entry and add the prop to it so the player can undo the spawn.
Source
Used by spawner systems for undo functionality.
Was this helpful?