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 FlyingFlambe · Oct 25, 2016 at 03:13 AM · listphysics2dcollider2dexplosion

Cannot create a 2D collider array

Hi, I'm having an issue where an error comes up saying "Cannot implicitly convert type 'UnityEngine.Collider2D' to 'UnityEngine.Collider2D[]'". I'm not sure how to resolve this, but after some reading I'm sure it has something to do with Lists, which is something I'm not familiar with yet (still learning programming).

The effect I'm attempting to create is a blowback effect (like an explosion pushing back entities around it), but only the Y-axis is affected. Haven't been able to test if the effect works yet, due to this error. Thank you for anyone who's able to provide advice.

 void BlowbackArea(Vector2 location, float blowbackRadius, float hpmMagnitude)
     {
         Collider2D[] objectsInRange = Physics2D.OverlapCircle(transform.position, 6.5f, whatIsHexPlate);
         foreach (Collider2D col in objectsInRange)
         {
             HexPlate hexPlate = col.GetComponent<HexPlate>();
             if (hexPlate != null)
             {
                 float proximity = (transform.position.y - hexPlate.transform.position.y);
                 float effect = 1 - (proximity / blowbackRadius);
             }
         }
     }
Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by hexagonius · Oct 25, 2016 at 08:31 AM

Physics2D.OverlapCircle only returns one Collider2D. That's why the error. Use OverlapCircleAll, which returns the desired array of Collider2Ds, which is probably what you intended to do

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
avatar image
1

Answer by MelvMay · Oct 25, 2016 at 09:56 AM

Better still use the non-allocating version OverlapCircleNonAlloc. Note you need to allocate an array that's large enough for the number of results you expect and pass that.

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
avatar image
0

Answer by FlyingFlambe · Oct 25, 2016 at 05:57 PM

Thanks @hexagonius and @MelvMay. I should've looked into it further ahh D: So simple. Much appreciated.

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
avatar image
0

Answer by FunkyPhoenixGames · May 07, 2018 at 09:49 AM

Wow what a coincidence... It just so happens that I was trying to do the same thing (an explosion affect) but I encountered this error! Thank you for helping me out @hexagonius and @MelvMay :)

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

81 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 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 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

Do I need Rigid2DBody if I don't plan to use physics? 2 Answers

Problems using RaycastHit2D.collider, detection only on the rays origin 1 Answer

How do I Implement Linecast2d 0 Answers

2d collisions physics not working when using mouse as input 0 Answers

Physics 2D disable collision bouncyness 0 Answers


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