Skip to main content
Version: 5.x
Supported on
Snapchat
Camera Kit

Camera Roll Widget

The custom component allows Snapchat users to select multiple photos from their Camera Roll. These images can then be used for collages, transitions, randomizers - use it whenever you want to keep track of what the user selected.

Adding the Component to a Scene

The Camera Roll Widget component can be downloaded from the Asset Library. Once installed, you can add it to your project from the Asset Browser panel by clicking the + button and searching for Camera Roll Widget.

Inputs

The component’s behavior can be customized through the following inputs in the Inspector panel.

InputTypeDescription
Max SelectionsnumberMaximum number of photos or videos a user can select at once (range: 2–20).
Media TypeenumThe type of media to be displayed in the media picker: "Images and Videos", "Images", or "Videos". When the value is changed, the media picker will be refreshed automatically.
Hide After All SelectedbooleanIf enabled, the camera roll closes automatically after the user selects the maximum number of items.
Set Selected MediabooleanIf enabled, displays selected photos or videos on a scene object using the Media Setter.
Media Setter InputMediaSetterInputSpecifies which objects display the selected media. Visible only if "Set Selected Media" is enabled.
Triggers InputTriggerStrategyInput[]Defines automatic actions triggered by user interactions, e.g., when a photo is selected.
Print WarningsbooleanIf enabled, shows helpful console messages when something isn't working correctly.
Print Debug MessagesbooleanIf enabled, displays extra debug information for troubleshooting.

Media Setter Input

This section specifies the target object for displaying selected media when Set Selected Media is enabled.

InputTypeDescription
Image Setter TypeenumType of object to display media on: Material, MaterialMeshVisual, VFXAsset, or VFXComponent.
MaterialMaterialSelect the material if "Material" is chosen.
Material Mesh VisualMaterialMeshVisualSelect the mesh if "MaterialMeshVisual" is chosen.
VFX AssetVFXAssetSelect the asset if "VFXAsset" is chosen.
VFX ComponentVFXComponentSelect the component if "VFXComponent" is chosen.
Property NamestringName of the texture property to change (default: baseTex).
Duplicate MaterialbooleanIf using "MaterialMeshVisual," this creates a copy of the material before applying the new texture.

Trigger Strategy Input

Defines automated actions based on user interactions with the camera roll. You can add multiple trigger strategies.

InputTypeDescription
Trigger TypeenumEvent that starts the action: OnSingleMediaSelected, OnSingleMediaDeselected, OnAllMediaSelected, or OnSelectionChanged.
ResponsesResponseStrategyInput[]Actions to perform when the trigger event occurs.

Response Strategy Input

Specifies the action performed when a trigger event occurs.

InputTypeDescription
Response TypeenumType of action: BehaviorScript, Tween, or CustomScriptApi.
Behavior Response TypeenumMethod for triggering the behavior: GlobalCustomTrigger or ManualTrigger. (Visible if Response Type is BehaviorScript).
Custom Trigger NamestringName of the trigger. (Visible if Behavior Response Type is GlobalCustomTrigger).
Behavior ScriptScriptComponentThe target behavior script. (Visible if Behavior Response Type is ManualTrigger).
Tween ScriptScriptComponentThe script containing the tween to play. (Visible if Response Type is Tween).
Custom ScriptScriptComponentThe script containing the function to call. (Visible if Response Type is CustomScriptApi).
Method NamestringName of the function to call in your custom script. (Visible if Response Type is CustomScriptApi).

Scripting API

To interact with the Camera Roll Widget from your own scripts, you can use its public API. It provides several events and methods to control the widget and respond to user selections.

Properties

NameTypeDescription
mediaTypeMediaType enumSpecifies the type of media to be displayed in the media picker. When the value is changed, the media picker will be refreshed automatically.

Methods

MethodDescription
show(): voidShows the media picker to the user with the configured options.
hide(): voidHides the media picker and clears all current selections.

Events

You can subscribe to events to trigger custom logic based on user interaction.

EventPayloadDescription
allMediaSelectedEventCameraRollMedia[]Triggered when all media slots (up to maxSelections) have been filled.
selectedMediaUpdateEventCameraRollMedia[]Triggered whenever the selection of media changes (an item is selected or deselected).
singleMediaSelectedEventCameraRollMediaTriggered when a single piece of media is selected by the user.
singleMediaDeselectedEventCameraRollMediaTriggered when a single piece of media is deselected by the user.

Example

Here’s how you can use the API to show the picker and listen for various events:

import { CameraRollWidget } from 'Camera Roll Widget.lsc/Camera Roll Widget';

@component
export class Test extends BaseScriptComponent {
@input
private readonly cameraRollWidget: CameraRollWidget;

onAwake() {
this.cameraRollWidget.singleMediaSelectedEvent.subscribe(
(media: CameraRollMedia) => {
print('Single media selected: ' + media.mediaId);
}
);
this.cameraRollWidget.singleMediaDeselectedEvent.subscribe(
(media: CameraRollMedia) => {
print('Single media deselected: ' + media.mediaId);
}
);
this.cameraRollWidget.allMediaSelectedEvent.subscribe(
(media: CameraRollMedia[]) => {
print('All media selected: ' + media.map((m) => m.mediaId).join(', '));
}
);
this.cameraRollWidget.selectedMediaUpdateEvent.subscribe(
(media: CameraRollMedia[]) => {
print(
'Selected media updated: ' + media.map((m) => m.mediaId).join(', ')
);
}
);
}
}

Types and Enums

MediaType enum

enum MediaType {
ImagesAndVideos,
Images,
Videos,
}

ImmutableEvent<T>

An object that allows you to subscribe to and unsubscribe from an event. The generic type T is a tuple representing the arguments passed to the listener.

MethodSignatureDescription
subscribe(listener: (...args: T) => void): SubscriptionSubscribes a listener to the event. Returns a Subscription object.
unsubscribe(listener: (...args: T) => void): voidUnsubscribes a listener from the event.

Subscription

An object with a dispose() method to stop listening to an event.

MethodSignatureDescription
dispose() => voidRemoves the event listener associated with this subscription.
Was this page helpful?
Yes
No