Compiler telling me raycast.collider is obsolete
In my code I have:
Collider2D playerFinder = Physics2D.OverlapCircle (transform.position, 5f, playerdetect);
if (playerFinder.collider != null) {
On that second line I am getting the error message:
'UnityEngine.Component.collider' is obsolete: 'Property collider has been deprecated. Use GetComponent() instead. (UnityUpgradable)'
But I'm clearly not trying to get a collider component, I'm trying to access the result of the OverlapCircle.
I have used the same method elsewhere, infact on the next few lines and yet I'm not getting errors for that. I got this error yesterday too and had to resort to using a OverlapCircleAll even though I didn't want to...
Am I doing something wrong or is this a bug?
That's what the compiler is telling me to do, but why? raycastname.collider is working in several other places and is 10x easier?
I have used the same method elsewhere, infact on the next few lines and yet I'm not getting errors for that
What exactly are the next few lines?
Answer by pako · Sep 12, 2015 at 04:43 PM
@checksumfail "collider" used to be a shortcut (quick property accessor) for easily accessing a GameObject's collider in previous versions of Unity. It has been deprecated to facilitate modularization of Unity:
http://blogs.unity3d.com/2014/06/23/unity5-api-changes-automatic-script-updating/
Also see the "SCRIPTING" section:
https://unity3d.com/unity/whats-new/unity-5.0
In your case, when you call the Physics2D.OverlapCircle method, you get a Collider2D in return, and you assign it to the playerFinder variable. So, since playerFinder is already a Collider2D, you shouldn't really try to access a collider component anyway, because it couldn't have one.
So, as @Positive7 says (+1), in your if condition you only need to use:
if (playerFinder != null)
I hope this makes sense.
Your answer
Follow this Question
Related Questions
StartCoroutine error message in C# 1 Answer
ForcedScopedThreadAttach 0 Answers
C# Greater Than or Equal To 1 Answer
Variable changing from other script does not work. 1 Answer
ArgumentNullException When using Collider2D.OverlapCollider() 1 Answer