Class ReloadAttribute
The ReloadAttribute attribute specifies paths for loading or reloading resources and has no direct action. Used with the ResourceReloader to define where to load data for null fields.
Inherited Members
Namespace: UnityEngine.Rendering
Assembly: Unity.RenderPipelines.Core.Runtime.dll
Syntax
[AttributeUsage(AttributeTargets.Field)]
public sealed class ReloadAttribute : Attribute
Remarks
This attribute is designed for use in the Unity Editor and has no effect at runtime.
UnityEngine.Rendering.IRenderPipelineResources have their own attribute ResourcePathAttribute to do this. When using them, resource reloading is handled automatically by the engine and does not require calling ResourceReloader.
While ResourceReloader was originally created for handling Scriptable Render Pipeline (SRP) resources, it has been replaced by UnityEngine.Rendering.IRenderPipelineResources. The ResourceReloader, ResourceReloader and ReloadGroupAttribute remain available for for user-defined assets.
Examples
This shows how to use the attribute in the expected scenario. This is particularly useful for content creators. Adding a new field to a class that defines an asset results in null values for existing instances missing the field in their serialized data. Therefore, when a new field is added, a system for reloading null values may be necessary.
using UnityEngine;
using UnityEditor;
public class MyResourcesAsset : ScriptableObject
{
[Reload("Shaders/Blit.shader")]
public Shader blit;
// Added in version 2
[Reload("Shaders/betterBlit.shader")]
public Shader betterBlit;
}
public static class MyResourceHandler
{
public static MyResourcesAsset GetAndReload()
{
var resources = AssetDatabase.LoadAssetAtPath<MyResourcesAsset>("MyResources.asset");
// Ensure that update of the data layout of MyResourcesAsset
// will not result in null value for asset already existing.
// (e.g.: added betterBlit in the case above)
ResourceReloader.ReloadAllNullIn(resources, "Packages/com.my-custom-package/");
return resources;
}
}
Constructors
ReloadAttribute(string, int, int, Package)
Creates a new ReloadAttribute for an array using automatic path name numbering.
Declaration
public ReloadAttribute(string pathFormat, int rangeMin, int rangeMax, ReloadAttribute.Package package = Package.Root)
Parameters
Type | Name | Description |
---|---|---|
string | pathFormat | The format used for the path |
int | rangeMin | The array start index (inclusive) |
int | rangeMax | The array end index (exclusive) |
ReloadAttribute.Package | package | The lookup method |
Examples
This example demonstrates handling arrays with resource paths that share a common format, differing only by an index.
using UnityEngine;
public class MyResourcesAsset : ScriptableObject
{
// The following will seek for resources:
// - Texture/FilmGrain/Thin1.png
// - Texture/FilmGrain/Thin2.png
// - Texture/FilmGrain/Thin3.png
[ResourcePaths("Texture/FilmGrain/Thin{0}.png", 1, 4)]
public Texture[] thinGrains;
}
See Also
ReloadAttribute(string, Package)
Creates a new ReloadAttribute for a single resource.
Declaration
public ReloadAttribute(string path, ReloadAttribute.Package package = Package.Root)
Parameters
Type | Name | Description |
---|---|---|
string | path | Search path |
ReloadAttribute.Package | package | The lookup method |
Examples
This example shows how to directly specify the path of an asset.
using UnityEngine;
public class MyResourcesAsset : ScriptableObject
{
[Reload("Shaders/Blit.shader")]
public Shader blit;
}
See Also
ReloadAttribute(string[], Package)
Creates a new ReloadAttribute for an array by specifying each resource path individually.
Declaration
public ReloadAttribute(string[] paths, ReloadAttribute.Package package = Package.Root)
Parameters
Type | Name | Description |
---|---|---|
string[] | paths | Search paths |
ReloadAttribute.Package | package | The lookup method |
Examples
This example demonstrates how to handle arrays with different resource paths.
using UnityEngine;
public class MyResourcesAsset : ScriptableObject
{
[ResourcePaths(new[]
{
"Texture/FilmGrain/Thin.png",
"Texture/FilmGrain/Medium.png",
"Texture/FilmGrain/Large.png",
})]
public Texture[] filmGrains;
}
See Also
Fields
package
The lookup method.
Declaration
public readonly ReloadAttribute.Package package
Field Value
Type | Description |
---|---|
ReloadAttribute.Package |
See Also
paths
Search paths.
Declaration
public readonly string[] paths
Field Value
Type | Description |
---|---|
string[] |