Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Teare · Apr 23, 2011 at 05:03 PM · errorrigidbodycollidertriggeraddforce

Check for rigidbody presence when in collision with a trigger

Hey, I have a setup where a box collider (is Trigger) is in front of the moving character. It follows the mouse and applies a rigidbody.AddForce on any object caught in the trigger.

This is supposed to apply only to props like crates and similar, but it also applies by default to objects without rigidbodies. Hence I get this error:

MissingComponentException: There is no 'Rigidbody' attached to the "platformA_1" game object, but a script is trying to access it. You probably need to add a Rigidbody to the game object "platformA_1". Or your script needs to check if the component is attached before using it. UnityEngine.Rigidbody.AddForce (Vector3 force) (at E:/BuildAgent/work/71ca6fec1b41cc30/Runtime/Export/Generated/NewDynamics.cs:469) fieldBehaviour.OnTriggerStay (UnityEngine.Collider collisionInfo) (at Assets/Scripts/behaviours/hero/fieldBehaviour.js:18)

It doesn't currently affect the game, but I get the ugly error and it interferes with debugging.

Is there any way to filter through the rigidbody.AddForce to only objects with a rigidbody? More specifically, how can I check if the Collider I get from

function OnTriggerStay (collisionInfo : Collider ) {

has a rigidbody attached to it or not?

thanks

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
Best Answer

Answer by Teare · Apr 23, 2011 at 06:14 PM

Thanks for anyone who viewed the question, but I found an easy solution on my own. The objects' lack of a rigidbody can be filtered out using

if(collisionInfo.rigidbody){

where the statement will only run if the object has a rigidbody attached

If anyone has an alternative I'd love to hear it

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 microp · May 11, 2011 at 06:02 PM

Hi! You might also want to look into layers. These could help you cull out unwanted objects and decide for which ones you want to receive collision and trigger callbacks at all (Edit/Project settings/Physics). I think this feature was introduced in Unity 3.0.

Still, your original solution looks very acceptable to me and might actually be easier ot maintain. The layer-based collision matrix can get pretty messy after a while and cause quite a few headaches! :)

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 Teare · May 17, 2011 at 04:42 AM 0
Share

Thanks for your comment there. I was actually using an older version of Unity and wasn't aware of the massive amount of updates that came with the newer version.

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

No one has followed this question yet.

Related Questions

Why do I get this error in such a simple script? 3 Answers

Simple Triggers problem. 1 Answer

Rigidbody2D alternating between TriggerEnter and TriggerExit? 1 Answer

isKinematic rigidbody collisions 3 Answers

col.gameObject.layer is not working 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