Class ReloadAttribute
The Reload
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.
Unity
While ResourceReloader was originally created for handling Scriptable Render Pipeline (SRP) resources, it has been replaced by Unity
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 Reload
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) |
Reload |
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 Reload
Declaration
public ReloadAttribute(string path, ReloadAttribute.Package package = Package.Root)
Parameters
Type | Name | Description |
---|---|---|
string | path | Search path |
Reload |
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 Reload
Declaration
public ReloadAttribute(string[] paths, ReloadAttribute.Package package = Package.Root)
Parameters
Type | Name | Description |
---|---|---|
string[] | paths | Search paths |
Reload |
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 |
---|---|
Reload |
See Also
paths
Search paths.
Declaration
public readonly string[] paths
Field Value
Type | Description |
---|---|
string[] |