Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
6
Question by Robotron18 · Dec 23, 2010 at 10:22 AM · collidermeshskinned

Collider on Skinned Mesh

Hello all.

I have Shinned Mesh with 2 bones for nonlinear Scalind (GO change from one side of axis). But Mesh Collider does not change its shape following the change in the mesh.

Maybe are there other methods for nonlinear Scaling if this unsolvable problem?

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 cregox · Apr 19, 2013 at 08:25 PM 0
Share

slightly related: http://answers.unity3d.com/questions/215678/raycast-without-colliders.html

4 Replies

· Add your reply
  • Sort: 
avatar image
13

Answer by rageingnonsense · Sep 23, 2015 at 05:49 PM

This is an old post, but I figured I would answer because there is a much simpler way to do this (at least in Unity 5, not sure if this would have worked at the time the question was posed):

     SkinnedMeshRenderer meshRenderer;
     MeshCollider collider;
    
     public void UpdateCollider() {
         Mesh colliderMesh = new Mesh();
         meshRenderer.BakeMesh(colliderMesh);
         collider.sharedMesh = null;
         collider.sharedMesh = colliderMesh;
     }

You would of course initialize the MeshCollider and SkinnedMeshRenderer.

This takes a snapshot of the deformed mesh, applies it to colliderMesh, then uses that for the MeshCollider. you just need to call it when you want to update the collider to match the mesh

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 Minsc · Jan 14, 2016 at 02:40 PM 0
Share

Thanks I will try it. I am not so sure about the slowdown, maybe it is very feasible with a proxy low poly mesh, I will make a test

avatar image CAN8ZABUZA · Feb 15, 2019 at 05:53 PM 0
Share

You save my life, this work's really well.

avatar image UnityVSF · Jun 14, 2019 at 01:14 PM 0
Share

You can just update it twice a second ins$$anonymous$$d of every frame:

         // Start is called before the first frame update
         void Start()
         {
             meshRenderer = GetComponent<Skinned$$anonymous$$eshRenderer>();
             collider = GetComponent<$$anonymous$$eshCollider>();
         }
     
         private float time = 0;
         // Update is called once per frame
         void Update()
         {
             time += Time.deltaTime;
             if (time >= 0.5f)
             {
                 time = 0;
                 UpdateCollider();
             }
         }
         
         Skinned$$anonymous$$eshRenderer meshRenderer;
         $$anonymous$$eshCollider collider;
         
         public void UpdateCollider() 
         {
             $$anonymous$$esh collider$$anonymous$$esh = new $$anonymous$$esh();
             meshRenderer.Bake$$anonymous$$esh(collider$$anonymous$$esh);
             collider.shared$$anonymous$$esh = null;
             collider.shared$$anonymous$$esh = collider$$anonymous$$esh;
         }
avatar image Bunny83 UnityVSF · Jun 14, 2019 at 02:31 PM 0
Share

Note that $$anonymous$$esh objects do not get destroyed automatically. So your code as well as the code in this answer will cause more and more memory to be allocated. If you want to create a new mesh each time you should destroy the old one. However it would make much more sense to reuse the same $$anonymous$$esh instance and just clear it before re-baking.

avatar image kardok · Jul 19, 2020 at 12:30 PM 0
Share

5 years has past and it still helps.

avatar image
5

Answer by Eric5h5 · Dec 23, 2010 at 03:07 PM

You wouldn't want the mesh collider to update with a skinned mesh even if it was possible, since it would be very slow. You can attach primitive colliders to bones instead.

Comment
Add comment · Show 7 · 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 Robotron18 · Dec 25, 2010 at 06:39 AM 0
Share

Update shared$$anonymous$$esh of $$anonymous$$esh Collider does not alter the shape collider. Changes only the base mesh. Is there a way to change the collider at runtime?

avatar image Robotron18 · Dec 27, 2010 at 03:10 PM 0
Share

If I could use a primitive Collider, certainly would have done it. But thanks.

avatar image Robotron18 · Dec 28, 2010 at 08:48 AM 0
Share

This is the first thing I did before asking a question. I'll try to solve the problem by any design method. Thank you.

avatar image cregox · Apr 19, 2013 at 04:21 PM 0
Share

That means manually going through each bone and adjusting the colliders to match the skinned mesh, right? And still not always get a satisfying result, depending on the mesh or on your needs... Also, way too troublesome. But, it has its usage, being the fastest way to process colliders and all. Lastly, yes we would want that for sporadic usage. ;-)

avatar image Minsc · Jan 14, 2016 at 07:38 PM 0
Share

I am not so sure about the slowdown, you can use a proxy low poly mesh of the skinned mesh and use that as a collider, better than primitive all over the bones. I will make a test.

Show more comments
avatar image
1

Answer by mattirwin · Jan 26, 2011 at 09:39 PM

I found a script to do this on the forum from user Darkrobyn. I believe this code reproduces the calculations that Unity is doing internally to deform the mesh.

It's working for me, but I currently have a fairly simple mesh and bone setup. I'm firing the forceUpdate occasionally (on mouse up events) which works great in my application.

Have a look here:

http://forum.unity3d.com/threads/14378-Raycast-without-colliders

The poster didn't include a couple of custom classes that you'll have to add. Something like this:

class CVertexWeight {

 public int index;
 public Vector3 localPosition;
 public float weight;

 public CVertexWeight(int i, Vector3 p, float w)
 {

     index = i;
     localPosition = p;
     weight = w;
 }

}

class CWeightList {

 public Transform transform;
 public ArrayList weights;
 public CWeightList()
 {
     weights = new ArrayList(); 
 }

}

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 Jessy · Jan 26, 2011 at 09:53 PM 0
Share

I read that at first as "CervixWeight". What's a C?!

avatar image Riderfan Jessy · Jan 14, 2016 at 03:41 PM 0
Share

Standard notiation for Class names.

avatar image mattirwin · Jan 26, 2011 at 10:17 PM 0
Share

A capital C is sometimes used as a prefix for class names to indicate that it's a class. I just followed the na$$anonymous$$g in the original script. If you download the original script you'll find those classes are missing.

avatar image cregox · Apr 19, 2013 at 04:53 PM 0
Share

works as a charm! and slow as hell as expected. :P

avatar image rajat · Aug 13, 2013 at 01:01 PM 0
Share

Thanks a lot for this, this is amazing :)

avatar image
0

Answer by itsnarutofan · Apr 15 at 03:19 PM

You Can Watch This Video :- https://youtu.be/M4IGWELxR9c

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

12 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

Related Questions

Mesh Collider Issue(?) - Raycast (ScreenPointToRay) Appears to Collide on Nothing 0 Answers

Assign a Mesh to Mesh Collider Automatically 1 Answer

Why attach a kinematic rigidbody to a collider that moves a lot? 1 Answer

Rigidbody objects not colliding. 4 Answers

Pushing a mesh with mesh collider 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