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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by firestorm713q · Apr 18, 2013 at 08:02 PM · collisionprocedural generation

Collision mesh won't form until mesh is moved?

I'm trying to use this(http://wiki.unity3d.com/index.php/MarchingSquares) script for a procedural 2d asteroid, and for whatever reason it creates the collision mesh, but won't form it until after I've moved it. Doesn't matter whether or not I move it in script or in the editor, but the collision mesh won't form. I'm still trying to wrap my head around building meshes procedurally, but I can't seem to figure out what I'm missing.

         // render
         // for the sake of simplicity we are rendering every frame.
         // obviously you should only render when the data of the cells has changed
         Mesh mesh, cmesh;
         MarchSquares(out mesh, out cmesh, ref cells, 0.5f);
         // update the render mesh
         mf = (MeshFilter) Testg.GetComponent(typeof(MeshFilter));
         mf.mesh.Clear();
         mf.mesh.vertices = mesh.vertices;
         mf.mesh.uv = mesh.uv;
         mf.mesh.triangles = mesh.triangles;
         mf.mesh.normals = mesh.normals;
         Destroy(mesh);
         // update the collision mesh
         MeshFilter cmf = (MeshFilter) TestRenderg.GetComponent(typeof(MeshFilter));
         cmf.mesh.Clear();
         cmf.mesh.vertices = cmesh.vertices;
         cmf.mesh.uv = cmesh.uv;
         cmf.mesh.triangles = cmesh.triangles;
         cmf.mesh.normals = cmesh.normals;
         Destroy(cmesh);
         mc = (MeshCollider) Testg.GetComponent(typeof(MeshCollider));
         if (mc != null)
             mc.sharedMesh = mf.mesh;
         
         Vector3 temp = Testg.transform.position;
         temp.y += 1;
         Testg.transform.position = temp;
     }
  
     public void FixedUpdate() {
         // render
         // for the sake of simplicity we are rendering every frame.
         // obviously you should only render when the data of the cells has changed
         Mesh mesh, cmesh;
         MarchSquares(out mesh, out cmesh, ref cells, 0.5f);
         // update the render mesh
         MeshFilter mf = (MeshFilter) Testg.GetComponent(typeof(MeshFilter));
         mf.mesh.Clear();
         mf.mesh.vertices = mesh.vertices;
         mf.mesh.uv = mesh.uv;
         mf.mesh.triangles = mesh.triangles;
         mf.mesh.normals = mesh.normals;
         Destroy(mesh);
         // update the collision mesh
         MeshFilter cmf = (MeshFilter) TestRenderg.GetComponent(typeof(MeshFilter));
         cmf.mesh.Clear();
         cmf.mesh.vertices = cmesh.vertices;
         cmf.mesh.uv = cmesh.uv;
         cmf.mesh.triangles = cmesh.triangles;
         cmf.mesh.normals = cmesh.normals;
         Destroy(cmesh);
         MeshCollider mc = (MeshCollider) Testg.GetComponent(typeof(MeshCollider));
         if (mc != null)
             mc.sharedMesh = mf.mesh;
     }


Comment
Add comment · Show 2
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 AlucardJay · Apr 19, 2013 at 04:05 PM 0
Share

I have read about (but never used) a trick where you disable and then enable the collider after the mesh has been modified.

avatar image firestorm713q · Apr 19, 2013 at 07:24 PM 0
Share

might also work.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by firestorm713q · Apr 19, 2013 at 12:30 AM

A dirty fix is to just move it up a unit, then back down, but I'd rather just have it make the object and go...if someone provides a better solution, I'll unmark this answer, but for now, this is my solution...

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 sparkzbarca · Apr 19, 2013 at 03:01 AM

how do you know the collision mesh isn't formed.

My guess is it is, most of the time though objects without rigidbodys are "asleep" that is why they don't collide right away.

If its because a collision doesnt happen at start do collider.awake() maybe or add a rigidbody.

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 firestorm713q · Apr 19, 2013 at 03:56 AM 0
Share

So the quoted script is only where the meshes are created and rendered. If you look through the linked marching squares script, there is a rigidbody attached, so that's not the issue. Also, collider doesn't have an awake function that I can call, as far as I can tell.

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

13 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

Related Questions

Colliders not Working with Tilemap Generation! 0 Answers

Custom collider for procedurally generated tiles 1 Answer

I want this script to update my mesh collider 0 Answers

Where do I add code to do procedural generation of environments? 1 Answer

How to Clamp A RigidBody to the Ground/ Moving a RigidBody Along the Ground 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