Open aavenel opened 4 years ago
Hi, thank you for submitting this. That's a fantastic idea for a rule.
I think this should also apply to mesh.colors
, which also copies the array before returning it.
While there isn't a separate count property for colors, it's my understanding that the array will (should?) always be same length as the .vertexCount
?
If that is the case, using int numColors = mesh.vertexCount
would avoid the silent array copy incurred by int numColors = mesh.colors.Length
.
If it is not the case, then at least a warning about the array copy incurred by accessing mesh.colors
.
Edit: Also mesh.colors32
, mesh.tangents
, etc...
Automatically adding "help wanted" tag for stale issues identified as good community contribution opportunities
I think I have implemented this. Is the repository still alive? I'll submit a PR if this is.
Sure, feel free to submit a PR.
Thanks!
mesh.vertices
returns a copy of all vertices. If you have code likemesh.vertices.Length
, this will be quite inefficient. It's much better to usemesh.vertexCount
or cachemesh.vertices
if you plan to use data from vertices array later.I have seen this at least one time in real code where there was code similar to this:
There is also a much worse offender which look a bit similar but is perhaps another issue:
while correct code should be something like this:
Unity Mesh API reference : https://docs.unity3d.com/ScriptReference/Mesh.html
I don't really know how to create an analyzer for this yet. I want to be sure that this is something useful and in the scope of this project first!