Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by Mercuri · Jan 10, 2021 at 08:02 AM · getcomponentphysics.raycastphysics.overlapsphere

GetComponent() failing for enemy colliders from OverlapSphereNonAlloc array, but working fine from Raycast output

Hi, I'm educated in CS, but I'm a beginner in Unity. Currently modifying the tutorial survival shooter by adding grenades.

Pulling my hair out a bit on this one, since the debugger shows the same gameobjects and colliders in both cases, but my GetComponent() call only returns null in the OverlapSphereNonAlloc case.

This Shoot() script correctly gets the EnemyHealth component from enemy colliders hit by Raycast, and applies damage correctly: Shoot script showing collider hit in debugger

Whereas this Explosion() script correctly identifies enemy colliders in range, but gets only nulls from the GetComponent() calls: Collisions are detected, but GetComponent fails

To my eye, these calls are the same in terms of class/hierarchy relationships... so I can't explain the failures in the grenade script. Unity version = 2020.2.1f1.

Would be really grateful for a pointer or two, so I can get back to building and learning! Thanks.

shoot-collider-enemyhealth.png (335.3 kB)
grenade-collider-enemyhealth-null.png (321.2 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by logicandchaos · Jan 10, 2021 at 12:50 PM

Line 71 try m_ExplosionHitCache[i].collision or collider.. I feel you are not pointing to the right object.

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 Mercuri · Jan 10, 2021 at 07:33 PM

Thanks for the suggestion.

I double checked that the third param of OverlapSphereNonAlloc() is of type static Collider[]. Also tried modifying to insert the .collider on line 71 and got this error indicating I was already on the collider component of the GameObject: "Assets_Complete-Game\Scripts\Weapons\GrenadierGrenade.cs(71,34): error CS0619: 'Component.collider' is obsolete: 'Property collider has been deprecated. Use GetComponent() instead. (UnityUpgradable)'

Just to be sure, I also went ahead and changed line 71 to EnemyHealth eh = m_ExplosionHitCache[i].GetComponent ().GetComponent ();

But there's no change to behavior, or to the m_ExplosionHitCache[i] objects when debugging

Comment
Add comment · Show 1 · 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 Mercuri · Jan 10, 2021 at 07:35 PM 0
Share

BTW - apologies for the poor formatting. I'm using carriage returns and the "code sample" button in the toolbar here, but the formatting seems to be lost/stripped when I post.

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

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

Mixing OverlapSphere and raycast physics to filter list 0 Answers

using Physics.Raycast to run functions on diffrent gameObjects? 1 Answer

How to Access Components in Children of GameObject? 1 Answer

GameObject info 2 Answers

I'm having more problems accessing a variable from another script in c# 2 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