Skip to content
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

Repeated property access could be improved with awareness of SetPositionAndRotation #2413

Open
vertxxyz opened this issue Aug 24, 2023 · 1 comment

Comments

@vertxxyz
Copy link

The detection of:

transform.localPosition = Vector3.zero;
transform.localRotation = Quaternion.identity;
// Or
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;

And turning it into:

transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
// Or
transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);

Would be a great way to help notify users that these combined APIs exist, instead of making their code grow by introducing a local variable when it may not be necessary.

(Do note that SetLocalPositionAndRotation was introduced in 2021.3.11f1)

@benblo
Copy link

benblo commented Sep 21, 2023

This (and many more) is already implemented by Microsoft's (UnityVS) Roslyn Analyzers: https://github.com/microsoft/Microsoft.Unity.Analyzers/blob/main/doc/UNT0022.md
It's be great is those analyzers where shared between VS and Rider...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants