CoplayDev/unity-mcp · error · ArgumentException
Screenshotter cannot be null
Error message
Screenshotter cannot be null
What it means
Thrown by TypePreviewGeneratorFromScene.ValidateSettings when Settings.Screenshotter is null. The scene-based preview generator requires a screenshotter instance to capture previews of objects in a scene. This validation runs after the base class InputPaths/OutputPath checks.
Source
Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/TypePreviewGeneratorFromScene.cs:29
namespace AssetStoreTools.Previews.Generators.Custom.TypeGenerators
{
internal abstract class TypePreviewGeneratorFromScene : TypePreviewGeneratorBase
{
protected new TypePreviewGeneratorFromSceneSettings Settings;
private CancellationTokenSource _cancellationTokenSource;
public TypePreviewGeneratorFromScene(TypePreviewGeneratorFromSceneSettings settings) : base(settings)
{
Settings = settings;
}
public override void ValidateSettings()
{
base.ValidateSettings();
if (Settings.Screenshotter == null)
throw new ArgumentException("Screenshotter cannot be null");
}
protected sealed override async Task<List<PreviewMetadata>> GenerateImpl(IEnumerable<UnityEngine.Object> assets)
{
var originalScenePath = EditorSceneManager.GetActiveScene().path;
await PreviewSceneUtility.OpenPreviewSceneForCurrentPipeline();
try
{
_cancellationTokenSource = new CancellationTokenSource();
EditorSceneManager.sceneOpened += SceneOpenedDuringGeneration;
return await GeneratePreviewsInScene(assets);
}
finally
{
EditorSceneManager.sceneOpened -= SceneOpenedDuringGeneration;
_cancellationTokenSource.Dispose();
if (!string.IsNullOrEmpty(originalScenePath))
View on GitHub (pinned to c21bf496bc)
Solutions
- Create and assign a screenshotter instance (e.g., a SceneScreenshotter subclass) to Settings.Screenshotter before calling Generate.
- Initialize the screenshotter in a settings factory method alongside dimension validation.
- If deserializing settings, reconstruct the screenshotter programmatically after load.
Example fix
// before
var settings = new TypePreviewGeneratorFromSceneSettings { InputPaths = paths, OutputPath = outPath, Screenshotter = null };
var generator = new TypePreviewGeneratorFromScene(settings);
await generator.Generate();
// after
var screenshotter = new SceneScreenshotter(screenshotSettings);
var settings = new TypePreviewGeneratorFromSceneSettings { InputPaths = paths, OutputPath = outPath, Screenshotter = screenshotter };
var generator = new TypePreviewGeneratorFromScene(settings);
await generator.Generate(); Defensive patterns
Strategy: validation
Validate before calling
if (settings.Screenshotter == null)
settings.Screenshotter = new SceneScreenshotter(CreateDefaultScreenshotSettings());
// or validate:
if (settings.Screenshotter == null)
throw new InvalidOperationException("A Screenshotter instance must be assigned before generation."); Type guard
static bool HasValidScreenshotter(TypePreviewGeneratorFromSceneSettings s)
=> s?.Screenshotter != null; Try / catch
try
{
await generator.Generate();
}
catch (ArgumentException ex) when (ex.Message.Contains("Screenshotter cannot be null"))
{
settings.Screenshotter = new SceneScreenshotter(CreateDefaultScreenshotSettings());
await generator.Generate();
} Prevention
- Construct the screenshotter in the same factory method that builds the settings.
- Reconnect non-serializable references like Screenshotter after deserialization.
- Validate Screenshotter assignment in the UI before allowing generation to start.
When it happens
Trigger: Calling Generate() or ValidateSettings() on a TypePreviewGeneratorFromScene with Settings.Screenshotter == null. The screenshotter is used in GeneratePreviewsInScene to capture each object.
Common situations: Settings constructed without assigning a Screenshotter; screenshotter field was cleared during settings reset; deserialized settings where the screenshotter (a non-serializable object reference) was not reconnected; UI didn't create the screenshotter before starting generation.
Related errors
- Width should be larger than 0
- Height should be larger than 0
- Depth should be larger than 0
- Native width should be larger than 0
- Native height should be larger than 0
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/23d1731c4168d8de.
Report an issue: GitHub.