public abstract class Editor.Asset
Related Guides
Broader workflow and conceptual references connected to this API.
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.
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.
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.
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.
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.
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.
No results match this filter.
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 Editor.Asset.PublishSettings Editor.Asset.Publishing { get; set; }
Access the asset publisher config.
public string Editor.Asset.RelativePath { get; set; }
The relative path as it is on disk (ie .wav not .vsnd)
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | Editor |
| Type | class |
| Assembly | Sandbox.Tools |
| Doc ID | T:Editor.Asset |