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 MoschPitt · Jun 30, 2015 at 12:16 PM · 2draycasting

Converting "old" raycasting method in 2d scene to new event system, now raycast is being "absorbed" by specific layer

I am in the process of converting a 2d scene that used the "old" method of raycasting through all objects and using broadcast to those objects.

  • I have added two new layers to my scene: "Navigation" and "ClickableObjects"

  • I have replaced the "old" raycasting/broadcast function on the main (and only) camera with a Physics 2D raycaster. the physics 2d raycaster is set to broadcast to only the "Navigation" and "ClickableObjects" layers.

  • I have a NAVMESH game object that has a polygon collider 2d which illustrates the "clickable walkable area" of the scene. It has a script so that, if clicked, the event system "Pointer Click" calls a function on the navmesh script on the units to move to that clicked location. The navmesh is in the "Navigation" layer

  • i also have clickable units throughout the scene. The idea is that, when these units are clicked, the will engage a chat window for the player to interact with. These units are in the "ClickableObjects" layer.

At this point, the navigation works as expected. The new event system sends a raycast to the NAVMESH which in turn calls the player units to move accordingly. This all works great.

However, the clickable objects no longer respond to clicks. In fact, the debug is never called on them that they registered a click. Now, if I walk over to them, disable the NAVMESH Physics 2d collider, and then click on the clickable objects, the chat window opens as expected. Also, if I move the clickable objects so that they are not "overlapping" the navmesh, everything works fine together.

I have tried the following to fix the problem: - adjusting the clickable units to be "closer to camera.main" on the z axis. No effect. - tried rearranging the layers to be in different order. No effect. Same issue. - tried creating separate physics 2d raycasters on the same camera to cast to specific layers. No effect. - tried creatiing a second camera with a raycaster casted to only one layer on each camera. no effect.

It seems that the NAVMESH polygon is absorbing the raycasts regardless of which layer it's configured to. Is there any way to cast a 2d ray to multiple, overlapping objects in the same layer without having one absorb the cast?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MoschPitt · Jul 01, 2015 at 10:31 AM

After 6 hours of trying different things, this was the solution that solved it: - On my navmesh gameobject (which consist of a polygon collider, an event trigger and a script to tell the units to "move here"), I put a sprite renderer. - I did not put a sprite on it--instead i simply used it to set the navmesh's sprite layer to the "ClickableObjects" layer and set the sort order to -9999 - Now the units are "in front of" the floor for a raycast and respond to clicks - When the player clicks anywhere there is not a unit, the floor catches the raycast

it's a pretty basic solution, though it seems a bit sloppy that I have to create an invisible sprite renderer on every clickable invisible area in the game just to control the ray cast priority, especially when those objects already have the appropriate 2d colliders and event triggers. Either way, I hope someone finds this helpful as it was the missing link to update my pre-Unity-4.6 game into the new event system and it works great!

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

1 Person is following this question.

avatar image

Related Questions

2D click on object with a raycast not working 2 Answers

How do I make ray cast to detect land? 1 Answer

How to find an object in front of player? 1 Answer

Physics.Raycast doesn't hit anything even though Debug.DrawRay works 1 Answer

2D Animation does not start 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