codeAPI Reference

s&box IToolActionEvents: Tool action callbacks

calendar_today May 12, 2026 schedule ~2 min read person PatrickJr verified 50

IToolActionEvents Interface API Reference

IToolActionEvents allows listening to tool actions across the scene. Implement this on a Component to receive callbacks before and after any tool action fires. Use this to enforce limits (e.g. max balloons, max constraints) or react to tool usage.

Type Signature

CSHARP
public interface IToolActionEvents : ISceneEvent<IToolActionEvents>
{
    public class ActionData
    {
        public ToolMode Tool { get; init; }
        public ToolInput Input { get; init; }
        public PlayerData Player { get; init; }
        public bool Cancelled { get; set; }
    }

    public class PostActionData
    {
        public ToolMode Tool { get; init; }
        public ToolInput Input { get; init; }
        public PlayerData Player { get; init; }
        public List<GameObject> CreatedObjects { get; init; }
    }

    void OnToolAction(ActionData e);
    void OnPostToolAction(PostActionData e);
}

Methods

OnToolAction(ActionData e)

Called before a tool action executes. Set ActionData.Cancelled to true to reject the action.

OnPostToolAction(PostActionData e)

Called after a tool action has executed successfully.

ActionData Properties

PostActionData Properties

Usage

CSHARP
public class BalloonLimiter : Component, IToolActionEvents
{
    private const int MaxBalloons = 50;

    void IToolActionEvents.OnToolAction(ActionData e)
    {
        if (e.Tool is Balloon)
        {
            var balloonCount = Scene.GetAll<BalloonEntity>().Count();
            if (balloonCount >= MaxBalloons)
            {
                e.Cancelled = true;
            }
        }
    }

    void IToolActionEvents.OnPostToolAction(PostActionData e)
    {
        if (e.Tool is Balloon)
        {
            // Log balloon creation
            Log.Info($"Created {e.CreatedObjects.Count} balloons");
        }
    }
}

Notes

  • Implements ISceneEvent for scene-wide broadcasting
  • Use for enforcing limits on tool usage
  • Use for reacting to tool actions (logging, stats, etc.)
  • Cancelled property prevents the action from executing
  • PostActionData includes created GameObjects for tracking
Was this helpful?