Unity code inspections
ReSharper's code inspection features are also supported in Unity-specific C# code. You can find the detailed information on these features in the corresponding topics of the Find code issues with code inspection section.
Examples of code inspections and quick-fixes
ReSharper shows warnings for unknown scenes, tags, and layers.
When the Solution-wide analysis is enabled, ReSharper understands implicitly used fields and event functions and do not highlight them as not accessed.
Empty event functions are shown as dead code, with a quick-fix to remove them.
Using the
SyncVarAttributeinside any class other thanNetworkBehaviouris treated as an error.A quick-fix is suggested to create a serialized field from a usage of an unresolved symbol:
ReSharper ensures that all of your event functions have correct signatures: it highlights incorrect signatures and offers a quick-fix to correct them:
ReSharper warns you against using an inefficient string literal comparison with the
tagproperty, and provides a quick-fix to rewrite this as a call toCompareTag.ReSharper warns you if you try to use the
newkeyword to create a new instance of a class deriving fromMonoBehaviourorScriptableObject. A quick-fix is suggested to usegameObject.AddComponent<T>()orScriptableObject.CreateInstance<T>()instead.There are also inspections for the
[InitializeOnLoad]and[InitializeOnLoadMethod]attributes, ensuring that they have the correct method or constructor signatures, and ReSharper will grey out a redundant[InitializeOnLoad]attribute if the class doesn't have a static constructor, with a quick-fix to either quickly remove the attribute, or create the constructor.
List of Unity-specific code inspections
Unity (47 inspections)
Inspections in this category report code issues specific to Unity projects.
Inspection | |
|---|---|
Alternative non-allocating method available
| |
Avoid 'base.OnGUI()' in classes derived from 'PropertyDrawer'
| |
Cannot resolve component or scriptable object
| |
| |
DOTS: Inconsistent type keywords
| |
DOTS: The type specified must be a structure type
| |
Event function with the same name is already declared
| |
Expected a type derived from 'Component' or 'MonoBehaviour'
| |
Expected a type derived from 'ScriptableObject'
| |
Field of 'ComponentLookup' type must be updated before being used.
| |
File name should match the name of the assembly
| |
| |
| |
Incorrect Odin's group attribute type
| |
Member appears in multiple UI groups simultaneously
| |
Method referenced in string literal does not have the expected signature
| |
'MonoBehaviour' instances must be instantiated with 'GameObject.AddComponent<T>()' instead of 'new'
| |
Parameter should be derived from 'Component'
| |
Possible incorrect application of attribute to multiple fields
| |
| |
| |
| |
Prefer GUID-based assembly references
| |
Redundant attribute usage (attribute is redundant when applied to this declaration type)
| |
Redundant attribute usage (redundant 'FormerlySerializedAs' attribute)
| |
Redundant attribute usage (redundant 'HideInInspector' attribute)
| |
Redundant attribute usage (redundant 'InitializeOnLoad' attribute)
| |
Redundant attribute usage (redundant 'SerializeField' attribute)
| |
Redundant Unity event function
| |
Repeated access of property on built in component is inefficient
| |
| |
Scene is disabled in the build settings
| |
| |
Setting 'parent' property immediately after object instantiation is inefficient
| |
Short scene name is not unique
| |
String based graphics property lookup is inefficient
| |
String based lookup of component type is inefficient
| |
The index is missing in the build settings
| |
The input name is not defined in the Input manager
| |
The layer is not defined in the 'Tags & Layers'
| |
The resource is not defined in the project
| |
The same shortcut is defined for another menu item
| |
The tag is not defined in the 'Tags & Layers'
| |
There is no animator state with the same name in the project.
| |
There is no scene with the same name in the build settings
| |
| |
Use 'CompareTag' instead of explicit string comparison
|
Unity Burst Compiler Warnings (17 inspections)
Inspections in this category report warnings of the Unity Burst Compiler before the code is actually compiled.
Inspection | |
|---|---|
Accessing managed indexers is not supported
| |
Accessing managed methods is not supported
| |
| |
Burst: String.Format(format, ...) invalid argument type
| |
| |
Creating a managed type is not supported
| |
Debug logging functions only accept strings
| |
Function signature cannot contain managed types
| |
Loading from a non-readonly static field is not supported
| |
Loading managed type is not supported
| |
Shared static type parameter requires the unmanaged constraint
| |
Some SharedStatic`1.GetOrCreate overloads cause compiler errors
| |
String.Format(format, ...) only accepts string literals and const strings
| |
The 'foreach' construction is not supported
| |
Try statement is not supported
| |
| |
Writing to a static field is not supported
|
Unity Performance Inspections (5 inspections)
Inspections in this category report computationally inefficient patterns Unity projects.
Inspection | |
|---|---|
| |
| |
| |
Order of multiplication operations is inefficient
| |
Use jagged or one-dimensional array instead of multidimensional array
|