-
Notifications
You must be signed in to change notification settings - Fork 855
Fix potential NullReferenceException in URP/HDRP/SG material import #5840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…tPath fails for some reason. - Example case: if the asset has a ".mat" suffix but it's not a Material.
Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed. HDRP URP Shader Graph Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
if (material == null) | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should threat this an exception or log error. It feels risky we silently fail to process a material.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, I'm not sure. As I don't have a repro case, I'm working under the impression that these are not really materials, but some other assets that happen to have a .mat extension. But I'm not sure if that's even allowed or makes sense in any valid use case. Does unity have strict 1:1 mapping between asset file extensions and asset types? Perhaps this needs some deeper investigation...
Update: I was able to repro this finally on 21.2. |
Upon further examination and discussion with @RSlysz, it seems like the fix proposed here is not the correct one. The reason for |
Purpose of this PR
This PR fixes following cases:
The issue seems to be that sometimes
AssetDatabase.LoadAssetAtPath(asset, typeof(Material));
can produce a null material, even ifasset
is not null. This can happen for instance for assets that have the ".mat" suffix but are not actually of type Material.Testing status
The NullReferenceException was not reproduced locally, so the fix is not verified. Should be minimal risk.