NonAlloc in Unity is either deprecated or ineffective
Hi, just felt worth mentioning... I noticed Rider suggests "Use non-allocating method for ..." e.g. 'OverlapCircleNonAlloc'. But a Unity developer over at the Unity forums say they are deprecated or "tentatively deprecated".
His exact quote:
"Yeah, it's technically not deprecated because it would cause a lot of users to be frustrated but all 2D queries with "NonAlloc" suffix are tentatively deprecated. All 2D queries (without exception) have an overload that replaces these calls (that take an array) and also accept a list.
OverlapCircleNonAlloc -> OverlapCircle
RaycastNonAlloc -> Raycast
etc."
Please sign in to leave a comment.
Hello,
could you please share the code that produces this suggestion for you? Also, which version of Rider do you use?
Hello,
Has it appeared in code completion suggestions for you, or did you have an error or a warning produced by a usage of Physics2D.OverlapCircle()? Would it be possible for you to provide a screenshot?
Thank you in advance.
Unfortunately I can't provide a screenshot. I clicked something to make the suggestions disappear, and I can't find where to get them back for testing. However, this was the link from the suggestions: https://github.com/JetBrains/resharper-unity/wiki/Avoid-using-allocating-versions-of-Physics-Raycast-functions
I've tried to re-enable them in the Inspection Severity window, just for testing, but it doesn't seem to bring back the suggestions (see screen shot).
All I can say is sometimes when I typed "Physics2D.OverlapCircle" it suggested the "Physics2D.OverlapCircleNonAlloc", probably when dealing with arrays, but all "NonAlloc" suffixes seems to be tentatively deprecated according to Unity.
Hello,
Thank you for the details. As far as I understand from your description, you are referring to non-allocating methods popping up in completion suggestions. Unfortunately there's currently no way to exclude specific suffixes from completion suggestion, apologies about that. Feel free to submit a new feature request to our tracker.
Since these methods are not completely deprecated and are still present in the Unity API, they will be present in the completion suggestions.
Let me know if you have any other questions. Have a great day!
I'm sorry Ivan, but that answer is far from satisfactory. What Bacall is saying is that Rider is suggesting the usage of de-facto deprecated methods, while there are already better replacements provided by the Unity API.
The non-allocating warning need not be removed, rather, be updated to use the non-allocating overloads of the Raycast/Circlecast/etc methods, instead of the NonAlloc methods, which are stated to be deprecated in the near future by the Unity Documentation.
This bug still exists. I'll go open one over on the tracker for resharper. This has caused confusion and lead to pointless refactors as well
See deprecation notes from Unity:
https://docs.unity3d.com/ScriptReference/Physics2D.OverlapBoxNonAlloc.html
Edit, opened Issue on Resharper Unity github: https://github.com/JetBrains/resharper-unity/issues/2445
A whole year has passed, please fix :( Ivan Skorikov
Hi, folks,
Apologies for keeping you in the dark about this. We've had a quick discussion and decided that this needs to be addressed indeed. Thanks a lot for your feedback and continued patience! Please upvote RIDER-112462 Don't suggest using deprecated non-allocating methods in UnityEngine API and keep an eye on status updates in that issue.