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 siaran · Apr 12, 2015 at 06:41 PM · meshmeshcolliderdeformation

Cannot update meshcollider mesh?

Hey, so, I'm working on some mesh deformation thing, but running into some problem with the collider. Basically, it has a mesh collider and I cannot get it to update itself.

     //This should be an icosphere
     public Mesh mesh; 
     public MeshCollider mcollider;
 
     List<TerrainOperation> currentOperations = new List<TerrainOperation>();
 
     // Use this for initialization
     void Start () {
         mesh = GetComponent<MeshFilter>().mesh;
         mcollider = GetComponent<MeshCollider>();
 
     }
 
 
     void Update(){
 
 
         //do all terrain operations
         if(currentOperations.Count > 0){
 
             for(int i = 0; i < currentOperations.Count; i++){
                 currentOperations[i].Operate();
                 if(currentOperations[i].isFinished) currentOperations.Remove(currentOperations[i]);
             }
 
             //this does nothing?
             mcollider.sharedMesh = mesh; 
 
             //update collider -- this is too slow
             //DestroyImmediate(mcollider);
             //mcollider = gameObject.AddComponent<MeshCollider>();
         }
     }

My mesh updates just fine, so I thought, well, let's assign the updated mesh as the mesh for the meshcollider, no need to calculate everything again... unfortunately, nothing happens. I've tried just setting the vertices, but that also has no effect except that my mesh becomes permanently altered (still changed when I exit play mode, which I do not want).

The commented out code below that destroys the meshcollider and then creates a completely new one works fine, but is way too slow.

So, thoughts?

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
Best Answer

Answer by hbalint1 · Apr 12, 2015 at 10:32 PM

Maybe this can help:

http://answers.unity3d.com/questions/446910/changing-mesh-collider-at-run-time.html

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 siaran · Apr 12, 2015 at 11:21 PM 0
Share

Hey, thank you for your reply. Unfortunately, when I try to assign null to the collider mesh, and then assign the mesh again, I have no collision at all anymore, so it doesn't quite work.

(If I don't do that, I just keep my old mesh for the collider.)

avatar image siaran · Apr 12, 2015 at 11:50 PM 0
Share

Okay, after trying things out some more, that actually works...sometimes. And when it does it's just as slow as destroying and then adding a new meshcollider :(.

Guess I'll have to think some more on how to speed this up... (Yeah, sure 'don't update your meshcollider in update' is all well and good, but I'm not sure if that's really an option).

avatar image hbalint1 · Apr 13, 2015 at 07:34 AM 0
Share

I make a game where you can tracnsform into other objects and i used the same method. It works for me and it's really quick. I show you:

     public void Transform(string name)
     {
         print("There is a(n) " + name + " in front of the Player!");
 
         // Find the GameObject only once and store it for performance reasons
         
         GameObject target = GameObject.Find(name);
 
         // Change object mesh
 
         gameObject.GetComponent<$$anonymous$$eshFilter>().mesh = target.GetComponent<$$anonymous$$eshFilter>().mesh;
         
         // Change object collider
 
         if (target.collider.GetType() == typeof($$anonymous$$eshCollider))
         {
             my$$anonymous$$eshCollider.enabled = true;
             my$$anonymous$$eshCollider.shared$$anonymous$$esh = target.GetComponent<$$anonymous$$eshCollider>().shared$$anonymous$$esh;
             my$$anonymous$$eshCollider.convex = true;
         }
     }
avatar image siaran · Apr 13, 2015 at 06:13 PM 0
Share

that way of doing it is fine for an instant transformation, but I want $$anonymous$$e to be gradual, which means I'd have to update the mesh collider basically every frame...which is too slow :<

I think what I need is a heightmap-based collider that is wrapped around a sphere somehow. Should be doable but idk how right now... ugh.

avatar image siaran · Apr 17, 2015 at 07:38 PM 0
Share

accepting this answer because it did answer my question in the end even though it didnt work out like I wanted :|

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

19 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

Related Questions

Problem with collision detection in an animated object 1 Answer

2D Mesh Deformation? 0 Answers

moving hole 3 Answers

Why is raycast not working with mesh collider 0 Answers

How to remove internal triangle/faces when combining mesh 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