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 /
This question was closed Jan 26, 2015 at 04:04 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by PhoenixBlackReal · Jan 25, 2015 at 08:51 PM · collisioncollider

Get collision without attaching a script to every game object

I have a bunch of objects in my scene. The player can choose which object to move at any given time. I need to detect if the moving object is colliding with any of the other objects - this would be fairly simple with OnCollisionEnter() script attached to the moving object, but, since the player can move any of the objects, I would have to attach the same script to all of them. I'm looking for a work around. To put it more simply, say there are objects A and B, which collide, and there's an object C with a script on it, which returns true if said two objects collided. A and B have no scripts attached.

Comment
Add comment · Show 7
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 meat5000 ♦ · Jan 25, 2015 at 08:57 PM 0
Share

You can access the collider and hence the whole gameobject of a colliding object through an object colliding with it.

A player can know what he collided with.

You can not, however, access this information through a body not involved in the collision. You will need to add a routine to the colliding objects which passes on the information if you wanted to access this from the player.

avatar image PhoenixBlackReal · Jan 25, 2015 at 09:04 PM 0
Share

I suppose it'd be too good to be able to get collision information from an object not involved. Although, the collision still has the data, even if no scripts are attached, it is still visible and apparent. I just don't have any idea to properly access it.

avatar image PhoenixBlackReal · Jan 25, 2015 at 09:19 PM 0
Share

While this doesn't really solve anything, I'm glad to at least know that this idea will not work, therefore I will not spend another hour or two aimlessly searching. Please post this as an answer, so I could accept it. Thank you for you help :)

avatar image PhoenixBlackReal · Jan 25, 2015 at 09:59 PM 0
Share

Wait, what about hierarchy? The parent object is not directly involved in collision, but maybe I could find out if the child is colliding through the parent? Catching straws here.

avatar image meat5000 ♦ · Jan 25, 2015 at 10:01 PM 0
Share

Its the same notion :)

Show more comments

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by meat5000 · Jan 25, 2015 at 09:09 PM

The data is only really accessible through the OnCollision routine. This is why a script is needed; as when the function has finished executing the information is no longer accessible as its scope was limited to the function itself.

You will need to create a variable of type Collision outside of the OnCollision function and use this field to hand off he information.

Alternatively, pass it straight to a player or another object, nonetheless you will need to script it to access the data.

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

Follow this Question

Answers Answers and Comments

20 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

Related Questions

The force on a collider which is penetrating the other collider 1 Answer

Destroy the gameObject after seconds when not hit. 0 Answers

Unity Colliders are Overlapping/Intersecting 2 Answers

Collision Only being detected on one of the objects involved in the collision - C# 0 Answers

Colliding two GameObjects 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