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 ina · Mar 15, 2011 at 03:13 AM · androidtransformoptimizationremotelocalscale

transform.localScale very slow on device (contrary to Android Remote)

For some reason, transform.localScale is very slow when app is deployed independently to device, but it works smoothly in Android Remote

I've tried defining a global var to store the transform, but that doesn't make a difference. localScale appears to be dependent on framerate, and I am wondering if there are cons to putting this operation in FixedUpdate instead of Update?

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 spovf · Sep 21, 2011 at 10:40 AM

The slowdown issue is not the GameObject itself which you want to rescale, but its collider. Even if never using the collider, it is actually there and will be updated with a call to transform.localScale result in a more complex scaling.

The collider is used for physics and collision detection, if you do not need this, the solution is quite simple - just destroy the collider of your GameObject.

GameObject.Destroy ( myGameObjectrenderer.collider );

Happy Scaling!

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 syclamoth · Sep 21, 2011 at 10:52 AM 0
Share

Should mention that it is only a problem for $$anonymous$$esh Colliders- anything else can be scaled as much as you like. Also, this is not nessesarily the problem here.

avatar image Owen-Reynolds · Dec 10, 2011 at 08:06 PM 0
Share

Scaling 15 planes/frame (representing flickering fire) dropped me from 80 to 3 fps. Sure enough, the Unity plane comes with a mesh collider (why not a very skinny box? Beats me.) Taking it off solved the problem.

EDIT: Since it was fire. I didn't even want a collider. But even when I took off the meshCollider and test-added a box, frame rate was still fine.

avatar image ina · Dec 13, 2011 at 03:16 AM 0
Share

@Owen Reynolds - so you just removed the mesh collider at runtime when scaling, and added it back later?

avatar image spovf · Dec 15, 2011 at 09:56 AM 0
Share

@ina - when using a collider the scaling is slow. No matter if you destroy and then recreate it. Destroying works for me at runtime, right after creating it. I guess if you want to scale often and need a collider it's kind of a dilemma. Hope that will be fixed by the Unity guys somehow.

avatar image
0

Answer by Eric5h5 · Mar 15, 2011 at 03:30 AM

When something is running in the remote it's running on your computer, which is likely 10-50X faster than whatever phone you have.

localScale appears to be dependent on framerate

Nothing is dependent on framerate unless you program it that way. (Or, perhaps, everything is dependent on framerate unless you program it not to be.) In other words, there's nothing special about localScale.

I am wondering if there are cons to putting this operation in FixedUpdate instead of Update?

The usual cons, yes. FixedUpdate should only be used for applying physics forces.

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 ina · Mar 15, 2011 at 03:33 AM 0
Share

As I understand, each time you invoke .transform.localScale (etc), it's actually .GetComponent("Transform").localScale - which was why I assigned a global to avoid having to traverse each time... I'd like a smooth transition of localScale, hence why it is in the update state.

avatar image ina · Mar 15, 2011 at 03:35 AM 0
Share

What is the usual con for FixedUpdate anyway? Would it be the app crashing due to the interval being too frequent and device not being able to catch up with it?

avatar image Eric5h5 · Mar 15, 2011 at 04:40 AM 0
Share

1) Tying transform operations to FixedUpdate means they don't update at the same rate the camera does, so they wouldn't look smooth. 2) If you're not actually using physics, you want to set the fixed timestep as high as possible to save CPU time (since you can't turn physics off completely), in which case code in FixedUpdate will also only run occasionally. 3) If you set the fixed timestep to a reasonably high rate, that means code in FixedUpdate is forced to try running at that speed even in low fps situations, which is the opposite of what you want in that case.

avatar image Eric5h5 · Mar 15, 2011 at 04:40 AM 0
Share

As far as caching transform in a variable, that's fine, and so is using localScale in Update.

avatar image ina · Mar 16, 2011 at 08:44 AM 0
Share

hm do you have any tips on improving localScale efficiency on device

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why does my game require so much rendering power? 1 Answer

Best transparent shader for Android devices 1 Answer

Why does the internal profiler show no GPU usage? 1 Answer

Sprite-based animation - mobile memory issue 0 Answers

Calling gameobject.transform vs. just calling transform directly - Performance negligible? 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