s&box docs

public abstract class Editor.Asset

Broader workflow and conceptual references connected to this API.

Asset Previews

If you want a specific file/asset type to have a custom Thumbnail/Inspector Preview, you can simply create an AssetPreview. An AssetPreview initializes a SceneWorld and SceneCamera, rendering the Camera to the Preview output, so all you need to do is populate it and/or position the Camera to your liking.

Binary Serialization

In the event that you find your JSON files growing too much due to too much data. You can store data as a binary blob. This will work with anything that serializes to JSON.

Cloud Assets

There is a large selection of Assets (Textures, Models, Sounds, ect) available to use on sbox.game, and you can use them without needing to think about downloading the files/mounting the content/ect.

Creating Mounts

The mount system is extensible - anyone can write a mount to add support for a new game or engine and contribute it to s&box via pull request. A mount detects a game's install directory via Steam, scans its files, and converts assets into s&box compatible assets, all at runtime.

Custom Assets

You can define your own custom asset types as GameResources. They give you a nice inspector window and they're hotloaded in-game, which means you can whip things up pretty quickly if you're using them.

Custom Editors

When creating your own Classes/Structs/Assets/ect, you'll sometimes want custom editors that pair with them. For example, a Gradient Editor so you can visually see what the Gradient looks like instead of editing the Gradient as if it were a Struct with a list of Colours.

Methods

Showing 31 methods

public void CancelThumbBuild()

public virtual void ClearInMemoryReplacement()

Reverse the changes of SetInMemoryReplacement

public virtual bool Compile(bool full)

Forcibly recompile the asset.

Parameters

  • full: TODO

public virtual System.Threading.Tasks.ValueTask`1<bool> CompileIfNeededAsync(float timeout = 30)

Returns a task that will resolve when the asset is compiled. If the asset is already compiled, do nothing. Does not support maps.

Parameters

  • timeout: Default: 30

Returns

true if the compile was needed, and was successful.

public void Delete()

Delete this asset. Will send the source and compiled files to the recycle bin.

public System.Threading.Tasks.Task DumpThumbnail()

Renders the thumbnail and then saves it to disk.

public virtual string FindStringEditInfo(string name)

public virtual System.Collections.Generic.List`1<string> GetAdditionalContentFiles()

Gets additional content-side related files. This includes like .rect files for materials, all .fbx and .lxo files for models, etc.

public virtual System.Collections.Generic.List`1<string> GetAdditionalGameFiles()

Gets additional game-side files to be packaged (e.g. navdata). These are files that are loaded by managed code, not as native resources.

public Editor.Pixmap GetAssetThumb(bool generateIfNotInCache = True)

Returns the asset preview thumbnail, with fallback to the asset type icon if there is no preview.

Parameters

  • generateIfNotInCache: Default: True

public virtual string GetCompiledFile(bool absolute = False)

Returns the compiled file path, if the asset is compiled.

Parameters

  • absolute: Whether the path should be absolute or relative. Default: False

Returns

The compiled file path, or null if the asset was not compiled.

public virtual System.Collections.Generic.List`1<Editor.Asset> GetDependants(bool deep)

Returns assets that depend/use this asset.

Parameters

  • deep: Whether to recurse. For example, will also include maps that are using models which use this material asset, as opposed to returning just the models.

public virtual System.Collections.Generic.List`1<string> GetInputDependencies()

Gets input dependencies for an asset. This'll be tga's for a texture and stuff like that.

public virtual System.Collections.Generic.List`1<Editor.Asset> GetParents(bool deep)

Returns assets that are parents of this asset (i.e. this asset is a compiled child resource of the returned assets).

Parameters

  • deep: Whether to recurse up the parent chain.

public virtual Sandbox.Model GetPreviewModel()

Try to create a preview model if we're fbx, obj, etc

public virtual System.Collections.Generic.List`1<Editor.Asset> GetReferences(bool deep)

Returns assets that this asset references/uses.

Parameters

  • deep: Whether to recurse. For example, will also include textures referenced by the materials used by this model asset, as opposed to returning just the materials.

public virtual string GetSourceFile(bool absolute = False)

Returns the source file path, if the sources are present.

Parameters

  • absolute: Whether the path should be absolute or relative. Default: False

Returns

The source file path, or null if the source files are not present.

public virtual System.Collections.Generic.List`1<string> GetUnrecognizedReferencePaths()

Unrecognized reference paths listed by the data that could not be resolved into Asset*s

protected void LoadUserTags()

public virtual void OpenInEditor(string nativeEditor = null)

Try to open this asset in a supported editor. You can specify nativeEditor to open in a specific editor.

Parameters

  • nativeEditor: A native editor specified in enginetools.txt (e.g modeldoc_editor, hammer, pet..) Default: null

public void OverrideThumbnail(Editor.Pixmap pixmap)

Override the Assets thumbnail with given one.

public string ReadJson()

Try to get the raw Json string, for a managed asset type (a GameResource)

public void RebuildThumbnail(bool startBuild = True)

Delete existing cached thumbnail, optionally queuing for building a new one ASAP.

Parameters

  • startBuild: Queue building the new thumbnail ASAP, as opposed to waiting when it is actually needed and doing it then. Default: True

public virtual void RecordOpened()

Tell asset system that this asset was opened. Sticks it on the recent opened list.

public System.Threading.Tasks.Task`1<Editor.Pixmap> RenderThumb()

Immediately render a preview thumbnail for this asset, and return it.

Returns

The rendered preview thumbnail, or null if asset type does not support previews.

public virtual bool SaveToDisk(Sandbox.GameResource obj)

Save a game resource instance to disk. This is used internally by asset inspector and for asset creation.

Parameters

  • obj: The instance data to save.

Returns

Whether the instance was successfully saved or not.

public virtual bool SetInMemoryReplacement(string sourceData)

Set data for this asset which will be compiled in memory. This is used to preview asset changes (like materials) before committing to disk.

public bool TryLoadResource(T obj)

Try to load this asset as a `Sandbox.Resource` of given type.

Parameters

  • obj: Output resource on success, null on failure.

Returns

true if `obj` was successfully set.

Properties

Showing 23 properties

public string Editor.Asset.AbsolutePath { get; set; }

The absolute path as it is on disk (ie .wav not .vsnd)

public virtual bool Editor.Asset.CanRecompile { get; set; }

Can this asset be recompiled?

public bool Editor.Asset.HasCachedThumbnail { get; set; }

public virtual bool Editor.Asset.HasCompiledFile { get; set; }

True if we have a compiled file, and aren't just a source file

public virtual bool Editor.Asset.HasSourceFile { get; set; }

True if we have a source file, and aren't just a _c file

public bool Editor.Asset.HasUnsavedChanges { get; set; }

A free-use variable for the editor to use to portray that this asset somehow has changes that need to be saved to disk.

public virtual bool Editor.Asset.IsCloud { get; set; }

This asset is from the cloud, it's in the cloud folder

public virtual bool Editor.Asset.IsCompiled { get; set; }

Whether the asset is compiled.

public virtual bool Editor.Asset.IsCompiledAndUpToDate { get; set; }

Whether the asset is compiled and all dependencies are up to date. (Slower than IsCompiled)

public virtual bool Editor.Asset.IsCompileFailed { get; set; }

Whether the asset failed to compile.

public bool Editor.Asset.IsDeleted { get; set; }

Whether the asset is deleted or not. This can happen after `Editor.Asset.Delete` was called on it, or `Editor.Asset.AbsolutePath` is empty.

public virtual bool Editor.Asset.IsProcedural { get; set; }

If true then this asset is generated at runtime somehow. Possibly from a mount system.

public virtual bool Editor.Asset.IsTransient { get; set; }

This asset is generated in the transient folder. You don't need to see it, or keep it around. It will re-generate from something else.

public bool Editor.Asset.IsTrivialChild { get; set; }

The asset was generated from another asset compile and has no source asset of its own. For example model break gibs .vmdl, .vtex files for materials, etc.

public System.Nullable`1<System.DateTime> Editor.Asset.LastOpened { get; set; }

When the asset was last opened through the editor.

public Editor.MetaData Editor.Asset.MetaData { get; set; }

Asset type specific key-value based data storage.

public string Editor.Asset.Name { get; set; }

Name of the asset, usually the filename.

public Sandbox.Package Editor.Asset.Package { get; set; }

If this asset was downloaded from sbox.game then this will be the package from which this asset was downloaded. If not then it'll be null.

public string Editor.Asset.Path { get; set; }

The relative path with the asset extension. ie .wav becomes .vsnd

public string Editor.Asset.RelativePath { get; set; }

The relative path as it is on disk (ie .wav not .vsnd)

public Editor.Asset.AssetTags Editor.Asset.Tags { get; set; }

Tags for this asset, for filtering purposes in the Asset Browser.

Metadata

FieldValue
NamespaceEditor
Typeclass
AssemblySandbox.Tools
Doc IDT:Editor.Asset

On this page

Methodspublic System.Void CancelThumbBuild()public virtual System.Void ClearInMemoryReplacement()public virtual System.Boolean Compile(System.Boolean full)public virtual System.Threading.Tasks.ValueTask`1<System.Boolean> CompileIfNeededAsync(System.Single timeout = 30)public System.Void Delete()public System.Threading.Tasks.Task DumpThumbnail()public virtual System.String FindStringEditInfo(System.String name)public virtual System.Collections.Generic.List`1<System.String> GetAdditionalContentFiles()public virtual System.Collections.Generic.List`1<System.String> GetAdditionalGameFiles()public Editor.Pixmap GetAssetThumb(System.Boolean generateIfNotInCache = True)public virtual System.String GetCompiledFile(System.Boolean absolute = False)public virtual System.Collections.Generic.List`1<Editor.Asset> GetDependants(System.Boolean deep)public virtual System.Collections.Generic.List`1<System.String> GetInputDependencies()public virtual System.Collections.Generic.List`1<Editor.Asset> GetParents(System.Boolean deep)public virtual Sandbox.Model GetPreviewModel()public virtual System.Collections.Generic.List`1<Editor.Asset> GetReferences(System.Boolean deep)public virtual System.String GetSourceFile(System.Boolean absolute = False)public virtual System.Collections.Generic.List`1<System.String> GetUnrecognizedReferencePaths()public Sandbox.Resource LoadResource()public Sandbox.Resource LoadResource(System.Type resourceType)public T LoadResource()protected System.Void LoadUserTags()public virtual System.Void OpenInEditor(System.String nativeEditor = null)public System.Void OverrideThumbnail(Editor.Pixmap pixmap)public System.String ReadJson()public System.Void RebuildThumbnail(System.Boolean startBuild = True)public virtual System.Void RecordOpened()public System.Threading.Tasks.Task`1<Editor.Pixmap> RenderThumb()public virtual System.Boolean SaveToDisk(Sandbox.GameResource obj)public virtual System.Boolean SetInMemoryReplacement(System.String sourceData)public System.Boolean TryLoadResource(T obj)Propertiespublic System.String Editor.Asset.AbsolutePath { get; set; }public Editor.AssetType Editor.Asset.AssetType { get; set; }public virtual System.Boolean Editor.Asset.CanRecompile { get; set; }public System.Boolean Editor.Asset.HasCachedThumbnail { get; set; }public virtual System.Boolean Editor.Asset.HasCompiledFile { get; set; }public virtual System.Boolean Editor.Asset.HasSourceFile { get; set; }public System.Boolean Editor.Asset.HasUnsavedChanges { get; set; }public virtual System.Boolean Editor.Asset.IsCloud { get; set; }public virtual System.Boolean Editor.Asset.IsCompiled { get; set; }public virtual System.Boolean Editor.Asset.IsCompiledAndUpToDate { get; set; }public virtual System.Boolean Editor.Asset.IsCompileFailed { get; set; }public System.Boolean Editor.Asset.IsDeleted { get; set; }public virtual System.Boolean Editor.Asset.IsProcedural { get; set; }public virtual System.Boolean Editor.Asset.IsTransient { get; set; }public System.Boolean Editor.Asset.IsTrivialChild { get; set; }public System.Nullable`1<System.DateTime> Editor.Asset.LastOpened { get; set; }public Editor.MetaData Editor.Asset.MetaData { get; set; }public System.String Editor.Asset.Name { get; set; }public Sandbox.Package Editor.Asset.Package { get; set; }public System.String Editor.Asset.Path { get; set; }public Editor.Asset.PublishSettings Editor.Asset.Publishing { get; set; }public System.String Editor.Asset.RelativePath { get; set; }public Editor.Asset.AssetTags Editor.Asset.Tags { get; set; }Metadata