Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by checksumfail · Sep 12, 2015 at 03:19 PM · c#error messagecollider2d

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?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Positive7 · Sep 12, 2015 at 03:23 PM 1
Share
 if (playerFinder != null 

avatar image checksumfail Positive7 · Sep 12, 2015 at 03:26 PM 0
Share

That's what the compiler is telling me to do, but why? raycastname.collider is working in several other places and is 10x easier?

avatar image pako · Sep 12, 2015 at 04:47 PM 0
Share

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?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges