Files
Hasebe/Library/PackageCache/com.unity.addressables@42676f2a154e/Documentation~/analyze-custom-rules.md
T
2026-09-21 12:15:57 +03:00

4.2 KiB

Create custom rules for Addressables Analyze

You can create custom rules for the Addressables Analyze window with the AnalyzeRule class.

Create a custom rule

To create a custom rule, create a new child class of the AnalyzeRule class, and override the following properties:

  • CanFix: Set whether the rule is fixable or not.
  • ruleName: Set the display name of the rule, which is displayed in the Addressables Analyze window.

You'll also need to override the following methods:

RefreshAnalysis

RefreshAnalysis is the analyze operation. In this method, perform any calculations and cache any data you might need for a potential fix. The return value is a List<AnalyzeResult> list. Create a new AnalyzeResult for each entry in your analysis, containing the data as a string for the first parameter and a message type for the second (to optionally designate the message type as a warning or error). Return the list of objects you create.

If you need to make child elements in the TreeView for a particular AnalyzeResult object, you can delineate the parent item and any children with kDelimiter. Include the delimiter between the parent and child items.

FixIssues

FixIssues is the fix operation. If there's an appropriate action to take in response to the analyze step, execute it here.

Tip

If you set CanFix to false, you don't have to override the FixIssues method.

ClearAnalysis

ClearAnalysis is the clear operation. Any data you cached in the analyze step can be cleaned or removed in this method. The TreeView will update to reflect the lack of data.

Adding custom rules to the Addressables Analyze window

A custom rule must register itself with the GUI class using AnalyzeSystem.RegisterNewRule<TRule>, to display in the Addressables Analyze window. For example:

[!code-cssample]

AnalyzeRule classes

To make it faster to setup custom rules, Addressables includes the following classes, which inherit from AnalyzeRule:

  • BundleRuleBase is a base class for handling AnalyzeRule tasks. It includes some basic methods to retrieve information about AssetBundle and resource dependencies.
  • Check bundle duplicates base classes help check for AssetBundle dependency duplicates. Override the FixIssues method implementation to perform a custom action:

Additional resources