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 bridged · Jul 19, 2012 at 09:47 PM · instantiatemeshdelaymesh colliderconvex

Prevent lag/delay when enabling mesh collider (convex)

Hey,

I have a selfmade mesh with a mesh collider on it that is used to walk on and now I want to make a building that can be built on this mesh (strategy game like) so I am instantiating a prefab I put in resources. The prefab has a mesh collider too but has convex enabled so it can collide with the other mesh (non-convex mesh collider cannot collide with another non-convex mesh)

The Problem is now, that there is an about 1 second delay when creating the prefab with instantiate.

to reduce and analyse this problem to its ground, I created just a simple mesh with mesh collider convex on it and turn its convex on and off with a button and the problem still exists, here is the simple code:

 using UnityEngine;
 using System.Collections;
 
 public class Building : MonoBehaviour {
  
  // focus and states and stuff
  public int state = 0;
 
  // Use this for initialization
  void Start () {
  transform.collider.enabled = true;
  
  }
  
  // Update is called once per frame
  void Update () {
  if(Input.GetKeyDown (KeyCode.P))
  {
  transform.collider.enabled = !transform.collider.enabled;
  }
  }
 }

The object that has this script has a mesh collider and rigidbody on it and again there is an unaccaptable long delay / lag when pressing P.

Do you have any idea how to prevent that or what would be the best solution to instantiate prefabs with rigidbody and mesh collider (convex) without having this delay / lag?

Ah and by the way, I cannot enable just convex itself like described here: Unity3d Scripting Manual - MeshCollider.convex MonoDevelop just tells me (like unity itself) that there is no definition "convex" for UnityEngine.Collider

EDIT: Ok sorry I just saw that MonoDevelop doesn't have a problem with transform.collider.convex, just unity3d, here is the Error:

 Assets/Standard Assets/Scripts/Building.cs(19,73): error CS1061: Type `UnityEngine.Collider' does not contain a definition for `convex' and no extension method `convex' of type `UnityEngine.Collider' could be found (are you missing a using directive or an assembly reference?)

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 ScroodgeM · Jul 20, 2012 at 04:32 AM

cast Collider type to MeshCollider type first. 'convex' is a MeshCollider's property, not Collider's

Comment
Add comment · Show 8 · 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 bridged · Jul 21, 2012 at 02:54 AM 0
Share

I don't know what you mean

I can make a mesh collider in the script like

private $$anonymous$$eshCollider meshC;

(does this put a meshcollider on the object even when I don'T put one on it with unity itself?) and later write

meshC.enabled = true;

meshC.convex = true;

but I mean I already put the meshcollider on the object, if I delete it it acts just like the script is useless, so how does this work at all with the mesh collider when the script doesnt work and the component by unity "mesh collider" makes a lag / delay.

I don't get it

avatar image ScroodgeM · Jul 21, 2012 at 04:08 AM 0
Share

you should use something like this in script

private $$anonymous$$eshCollider meshCollider;

and in method changing convex property

if (!meshCollider) { meshCollider = gameObject.GetComponent<$$anonymous$$eshCollider>(); }
if (!meshCollider) { meshCollider = gameObject.AddComponent<$$anonymous$$eshCollider>(); }
meshCollider.convex = true;

the main thing is that 'Collider' is not '$$anonymous$$eshCollider'. 'Collider' type has only shared properties for all type of colliders. '.convex' property is only $$anonymous$$eshCollider's property so 'Collider' doesn't have it. if you want to change this property, you must cast your collider instance to type of $$anonymous$$eshCollider.

'transform.collider' can be a box collider as well for example - what should do 'transform.collider.convex = true;' then?

avatar image bridged · Jul 22, 2012 at 10:51 AM 0
Share

ah lol okey...

I just didn'T get it that $$anonymous$$eshCollider is a component and I have to handle it like one, now it is clear.

But the problem that there is a short delay is still there..

any idea?

avatar image ScroodgeM · Jul 22, 2012 at 10:54 AM 0
Share

making mesh collider as convex needs some calculations. why don't you do it in editor? you can create convex collider in editor and just enable it at runtime

avatar image bridged · Jul 22, 2012 at 11:02 AM 0
Share

I tried that too.

It's about instantiating buildings in the game (like a strategy game) and everytime I turn on the convex it makes this delay.

So like you see, I cannot just put them in the scene before.

but I'm thinking about using only a box collider for the bottom of the building to be able to put it on a meshcollider surface and make the rest of the building as a trigger and make the actual collider effect with a script

Show more comments

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

Convex mesh collider thinks model is non manifold but it isn't 1 Answer

Covex Mesh Collider help 1 Answer

Creating more objects with code. 2 Answers

How to Move two spheres over the surface of irregular shapes meshes towards the closest X and Y boundary of mesh without leaving its trigger till end.,? 0 Answers

How to delay a respawn? 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