Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
3
Question by Lexoka · Jun 18, 2013 at 07:00 PM · rigidbodycolliderkinematicprimitives

How to create and move primitives without the static collider penalty?

Hi,

I need to create a lot of primitives, place each primitive where it needs to go, and make each primitive a child of the same common parent object. Currently, I do just that:

 private void CreateMyGameObject(Vector3 location) {
     GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
     cube.transform.Translate(location);
     cube.transform.parent = commonParent.transform;
     // Some other, irrelevant stuff
 }

The problem is that this takes quite a bit of time (I need anywhere between a few to about 20,000 of those primitives) and according to the profiler, much of the cost comes from moving the static collider associated with each primitive. Apparently, said collider is created along with the primitive by CreatePrimitive().

But I don't really need this collider, nor do I need it to be static. How do I get around this problem? I figured adding a kinematic rigidbody to the object might do the trick, but it incurs extra work, memory allocation, and doesn't even appear to help.

If I could disable the creation of the collider, or ideally defer it to the point where the primitive has already been moved, that would be great. Is that possible?

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

· Add your reply
  • Sort: 
avatar image
1

Answer by whydoidoit · Jun 18, 2013 at 07:26 PM

Adding a kinematic rigidbody will remove the physics penalty - but I guess you should either:

a) Create a cube using something apart from primitives (a cube mesh you import perhaps?), create a prefab and make sure it doesn't have a collider then instantiate that.

b) Create a cube mesh on the fly using new Mesh() and add it to a game object with a Mesh Filter and a Mesh Renderer.

c) Destroy the collider attached to the primitive with Destroy(cube.collider);

Comment
Add comment · Show 4 · 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 Lexoka · Jun 20, 2013 at 02:08 PM 0
Share

Thanks whydoidoit.

I tried option c), but I'm a little confused by the results. If I do Debug.Log(cube.collider.ToString()), I get "null", as expected, however the profiler still shows this:

alt text

If the colliders no longer exist, why are they still being moved? Is the function automatically called whether a profiler exists or not? Or am I completely misinterpreting what the profiler is showing, and it's actually set_parent() itself that is expensive?

profiler_static_colliders.png (15.4 kB)
avatar image whydoidoit · Jun 20, 2013 at 02:47 PM 0
Share

It really looks like it thinks it still has a collider :S Are you sure it's gone in the scene during run?

avatar image whydoidoit · Jun 20, 2013 at 02:48 PM 0
Share

Set parent is a pretty expensive operation actually - do you have to do that often?

avatar image Lexoka · Jun 20, 2013 at 03:07 PM 0
Share

Well, I did a Debug.Log(cube.collider.ToString()) both before and after set_parent(), and got "null" each time, as expected. So the collider really does appear to be gone.

I do set_parent for each primitive I create, but they all have the same parent so if I understand correctly, I can get around that problem by creating the first one, setting its parent, and then instantiating all the others from the first one. From what I gather, if I do that, they will all share the same parent with a single call to set_parent().

I intend to try that, but I don't think it will help with the collider issue, since I still have to translate my cubes anyway.

avatar image
0

Answer by brikim13 · Feb 21 at 02:03 AM

I created a simple prefab (without the collider) in my asset folder.

Then I instantiated that object instead.

 GameObject cube = Instantiate(MySimpleObject);


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

16 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

Related Questions

Having a kinematic rigidbody detect collision with a collider without a rigidbody 7 Answers

How do I grab an object without going through it? 0 Answers

Kinematic Rigidbody Collider not colliding with Static Trigger Collider 3 Answers

Make isKinematic false when touching a Collider? 1 Answer

Using transform in kinematics rigid body 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