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
1
Question by Goron40 · Apr 15, 2012 at 07:18 PM · raycastcollidermeshbuildcrash

Raycast crashing build on collision with mesh collider

Alright, so I've got a segment of code here...

 // Get the ray going through the "center" of the screen
 var ray:Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width / 2, Screen.height * .6 , 0));
 
 // Do a raycast
 var hit : RaycastHit;
 if (Physics.Raycast (ray, hit))
 {
      Do things here...
 }

I've tested everything in and around this code and I'm 100% certain that the problem is with this line here:

 if (Physics.Raycast (ray, hit))

Now here's where it gets weird. In the editor, I have no problems and can run this code fine. However, if I build an exe of the project, it will crash as soon as I look at something with a mesh collider. Using primitives will not cause a crash.

The mesh colliders are checked as convex, and although they are over 255 triangles, Unity's clearly running a simplification algorithm (I can see the simplified mesh in the editor). I have also tried making my own >255 tri mesh and replacing the simplified collider with it, to the same effect.

Does anyone have any idea what's going on here?

Comment
Add comment · Show 1
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 Goron40 · Apr 15, 2012 at 08:31 PM 0
Share

As a test, I disabled all code in "Do things here..." and removed all scripts from the object being hit by the raycast. Still no luck.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Goron40 · Apr 15, 2012 at 09:41 PM

Alright, I "fixed" it. Built a 32 bit build instead of a 64 bit one. No idea why that did anything, I'm on a 64 bit computer. Very strange.

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 aldonaletto · Apr 15, 2012 at 11:00 PM 0
Share

There were lots of bugs and other problems reported with 64 bit versions in the past - it seems these issues have not been fixed yet...

avatar image
0

Answer by aldonaletto · Apr 15, 2012 at 07:43 PM

Weird thing! Unless some bug in your Unity version is causing this, there's nothing in your code to make it crash.
A shot in the dark: the most frequent cause of crashes in Unity is unintentional recursive loops. For instance: if the code inside if (Physics.Raycast(...)) calls a function in the hit object, and this function somehow calls the original code that does the raycast, an infinite recursive loop starts and quickly crashes Unity.
Are you calling some code in these meshes? Or even meshes without any script cause the crash? The crash still happens if you omit the code inside the if (Physics.Raycast(...))?

Comment
Add comment · Show 3 · 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 Goron40 · Apr 15, 2012 at 08:20 PM 0
Share

I took out all the code in the if loop to check this. No luck there.

All scripts have been removed from those meshes to test that theory. Still crashing.

avatar image aldonaletto · Apr 15, 2012 at 08:56 PM 0
Share

Well, it smells like a bug. How the crashing meshes were created? In some 3D editor? $$anonymous$$aybe some weird data in the model is causing the problem. To test this, you could get some Unity primitive (a cylinder, for instance) and replace the original collider with a mesh collider (Component->Physics->$$anonymous$$esh Collider - remember to set Convex). If this "native" mesh collider still causes the crash, you may have a defective Unity - reinstall it. If it doesn't crash Unity, your models may have some weird characteristic that's activating a Unity's bug - maybe saving the models in a different format and reimporting them could solve the problem.

avatar image Goron40 · Apr 15, 2012 at 09:12 PM 0
Share

I tried a primitive collider. No problems.

However, just discovered setting the build to 32bit avoids the crash.

avatar image
0

Answer by Sphax84 · Nov 28, 2016 at 12:30 AM

I get a crash on "Physics.Raycast (ray, hit)" as well on x64 (not tested on x86) when many raycasts are achieved in a loop. This happens in editor while playing or in standalone exactly the same.

I'm 100% sure my code is correct because it does not crash when few raycasts are done. By the way, even if my code wasn't ok, Unity editor or standalone should never crash...

I already reported it to Unity but they never wanted to investigate to fix that bug... :(

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Win x86_64 build crashes on Opcode 1 Answer

How to Detect All Mesh Triangles Within a Given Area 2 Answers

Returning list of Triangles, Vertices or Points by raycasting through a mesh (iPhone) 1 Answer

Editor vs Build: OnTriggerStay & Physics Issues 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