Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Sep 11, 2019 at 01:18 PM by koptehe for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by koptehe · Sep 09, 2019 at 01:55 PM · collisioncollidermeshcollidercollide

Mesh Collider doesn't work without reset

Hello, everyone!

I proceed my own mesh, and I want it interactable. But when I add a AddComponent(); in the code, it doesn’t work in the game.

If during the game I turn off and turn on the component again in the inspector panel, it works as needed.

Please, help me. I don't understand, why it happens.

P.S. Blue circle is gaze and surface collide feedback from HoloToolkit for Mixed Reality.

P.P.S. I create GameObject, create surface and add mesh collider as GameObject.AddComponent();

EDITED

 GameObject go= new GameObject(name);
  go.transform.SetParent(parent.transform);
  
  MeshFilter filter = go.AddComponent<MeshFilter>();
  Mesh mesh = filter.mesh;
          
  MeshRenderer mr = go.AddComponent<MeshRenderer>();
 
 // something
 
  mesh.vertices = points.ToArray();
  mesh.triangles = triangles.ToArray();
  mesh.RecalculateNormals();
  
  go.AddComponent<MeshCollider>();

Before reboot Mesh ColliderAfter reboot Mesh Collider

after-reboot.png (235.6 kB)
before-reboot.png (318.6 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

  • Sort: 
avatar image
0
Best Answer

Answer by koptehe · Sep 11, 2019 at 01:17 PM

I've solved it. I have 2 scripts. In the first, I called a function (second script) in which I created the mesh. And after that I changed my parent in the first.

Thus, you must firstly set the parent, and then create the mesh.

But why so, I did not understand (

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 Pangamini · Sep 09, 2019 at 02:04 PM

Do you also set the meshCollider's mesh? This is done in editor in Reset() (or when the component is added) but not when you do it in code. Just adding a meshCollider to a gameObject with a mesh renderer and filter won't automatically assign the same mesh to the collider

Comment
Add comment · Show 5 · 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 koptehe · Sep 09, 2019 at 02:39 PM 0
Share

Yes, I add $$anonymous$$eshCollider component. I add it like this:

 GameObject go= new GameObject(name);
 go.transform.SetParent(parent.transform);
 
 $$anonymous$$eshFilter filter = go.AddComponent<$$anonymous$$eshFilter>();
 $$anonymous$$esh mesh = filter.mesh;
         
 $$anonymous$$eshRenderer mr = go.AddComponent<$$anonymous$$eshRenderer>();

do something and...

 mesh.vertices = points.ToArray();
 mesh.triangles = triangles.ToArray();
 mesh.RecalculateNormals();
 
 go.AddComponent<$$anonymous$$eshCollider>();
avatar image Pangamini koptehe · Sep 09, 2019 at 02:42 PM 0
Share
 $$anonymous$$eshCollider collider = go.AddComponent<$$anonymous$$eshCollider>();
 collider.shared$$anonymous$$esh = mesh;

Also, access $$anonymous$$eshFilter.shared$$anonymous$$esh ins$$anonymous$$d of mesh, the latter creates a copy of the mesh

avatar image koptehe Pangamini · Sep 09, 2019 at 02:47 PM 0
Share

Unfortunatly, it doesn't work :( Nothing changed

Show more comments

Follow this Question

Answers Answers and Comments

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

How to do collision of external objects on script? 1 Answer

Anyway to make my object not fall through the floor without convex? 0 Answers

How do i understand which gameObject is player touching ? 1 Answer

Destroy cube when player collides -1 Answers

Random Collision on PlayerCharacter? 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