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
2
Question by Panzerhandschuh · Mar 28, 2013 at 07:51 AM · collidermeshscaleframerate

Scaling object in Update() causes significant frame rate issues

Basically I'm trying to make a particular object scale based on its distance from the camera, which means I have to scale it in Update(). Here is a pic to show what I'm doing: http://i.imgur.com/83d1aeP.png

The problem is that when I scale this object, it also scales the colliders which kills performance. The profiler tells me "Mesh.Bake Scaled Mesh PhysX Collision Data" is taking up 76.8% of processing time (~2000 fps -> ~200 fps with v-sync off).

Is there any way to scale the MeshFilters only and not the colliders? Or is there a way I can scale the vertices on the MeshFilters? The object is composed of multiple filters/colliders so I can't really just scale the mesh.vertices for each MeshFilter (they will scale relative to their own centers/pivot points, not relative to that grey center dot in the pic above).

I still need the MeshCollider to be available and I would just update it before doing any ray casting so I can't just delete it. If anyone can help me out then I'd really appreciate it.

Here's my current code for scaling:

 Vector3 distance = transform.position - Camera.main.transform.position;
 transform.localScale = Vector3.one * 0.03f * Vector3.Dot(distance, Camera.main.transform.forward);

Comment
Add comment · Show 12
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 whydoidoit · Mar 28, 2013 at 08:34 AM 1
Share

Wouldn't you be better off using another camera to render that object at the same location as the world x/y coordinates converted to the camera's screen coordinates? That way it wouldn't have to change size...

avatar image Panzerhandschuh · Mar 28, 2013 at 09:01 AM 0
Share

I need the collider because I'm doing ray casts on it. If you look at the picture (http://i.imgur.com/83d1aeP.png), you will see some arrows which are all selectable if you click them.

Whydoidoit, that solution seems great but how exactly would I go about doing it?

avatar image Panzerhandschuh · Mar 28, 2013 at 10:00 AM 1
Share

Alright, I'll try that out. I've never really messed with cameras like this before. Just so you guys are clear, I'm making something very similar to how the built in move tool works in unity. I appreciate the help and I'll let you guys know how it goes.

avatar image Panzerhandschuh · Mar 30, 2013 at 07:28 AM 1
Share

I've been messing with colliders a lot today and I managed to get some pretty good results. Scaling Box/Capsule colliders every frame isn't nearly as bad as scaling $$anonymous$$eshColliders, but I managed to get even better fps using a similar method to what I did with the $$anonymous$$eshColliders. I basically just add a new Box/Capsule Collider component to the object right before selection and delete the component after selection/raycasting. Here's the code for creating a collider for one of the arrows:

 CapsuleCollider xAxisCollider =
     GameObject.Find("TransformAxisX").AddComponent<CapsuleCollider>();
 xAxisCollider.radius = 0.05f;
 xAxisCollider.height = 1.2f;
 xAxisCollider.direction = 0;

This code barely even makes a mark in the profiler.

So in the end, I get about 2300 fps while the objects are being rendered which is much better than before. I really appreciate the advice on using box/capsule colliders since it definitely helped performance a lot.

avatar image Panzerhandschuh · Mar 30, 2013 at 08:28 AM 1
Share

With the create/destroy collider method, I get ~2300 fps opposed to ~1900 fps with just constantly scaling the colliders, so I think it was worth it. $$anonymous$$y game has some pretty heavy math calculations running every frame so it's nice to have some extra cpu power available.

Show more comments

2 Replies

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

Answer by Fattie · Mar 28, 2013 at 08:01 AM

1 - Only scale the collider (say) once every second, or, indeed only scale it "on demand". (i.e.: Keep a flag whether it's been scaled or not, and only do so when you need it.)

2 - Don't use a mesh collider. In a word, they are almost never used in games. They are never used in UI.

Comment
Add comment · Show 2 · 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 Panzerhandschuh · Apr 03, 2013 at 06:28 PM 1
Share

Alright, but anyone with similar issues reading this should also read all of the comments to the first post.

avatar image Fattie · Apr 03, 2013 at 06:29 PM 0
Share

particularly for the excellent statistics you posted, thanks for that

avatar image
0

Answer by Paulius-Liekis · Apr 03, 2013 at 09:19 AM

  1. Don't use mesh collider. If it's a sphere then use sphere collider :)

  2. I assume you need collider only when you're close. Maybe disabling the collider will stop it from being scaled?

  3. Put Collider and MeshRender on different GameObjects and scale only renderer.

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

14 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

Related Questions

Mesh Collider from 3d max animation? 1 Answer

Scale collider independent of gameObject. 1 Answer

Scaling the Mesh Collider 4 Answers

Can you scale a Mesh independently of it's Collider? 1 Answer

Why does unity re-scale mesh when using mesh collider? 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