codeAPI Reference

s&box IResourcePreview: Resource preview interface

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

IResourcePreview Interface API Reference

IResourcePreview is an interface for GameResources that want to enable in-picker previewing. When the user clicks an item in the resource picker, OnPreview is called instead of immediately selecting it. A "Select" button confirms the choice.

Type Signature

CSHARP
public interface IResourcePreview
{
    void OnPreview();
    void OnPreviewStop();
}

Methods

OnPreview()

Called when the user clicks this resource in the picker for preview. Use this to play a sound, show a visual, etc.

OnPreviewStop()

Called when the preview should stop (another item previewed, picker closed, or resource selected).

Usage

Implement on a GameResource to enable preview functionality:

CSHARP
[AssetType(Name = "Sound Definition", Extension = "sndef", Category = "Sandbox")]
public class SoundDefinition : GameResource, IResourcePreview
{
    [Property] public SoundEvent Sound { get; set; }

    private SoundHandle _previewHandle;

    public void OnPreview()
    {
        OnPreviewStop();

        if (Sound is null) return;
        _previewHandle = Sandbox.Sound.Play(Sound);
    }

    public void OnPreviewStop()
    {
        if (_previewHandle.IsValid())
        {
            _previewHandle.Stop();
            _previewHandle = default;
        }
    }
}

Notes

  • Used by the resource picker to enable preview before selection
  • OnPreview should stop any previous preview before starting a new one
  • OnPreviewStop should clean up any preview resources
  • Commonly used for sounds (play audio), models (show ghost), particles (spawn preview)
  • Preview is shown in the resource picker UI
Was this helpful?