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 username707 · Jul 23, 2013 at 04:00 PM · vector3performanceupdate

How to cycle Vector3 transformations correclty perfomance-wise?

Just learned that multiple Vector3 transforms in cycle on Update can hit performance very bad. Is there any other way to move objects around instead of Vector3.

Comment
Add comment · Show 4
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 robertbu · Jul 23, 2013 at 04:10 PM 1
Share

Need some context about what you are trying to do: Learned from where? Are we talking about a dozen, hundreds, thousands? What platform? Are you caching your transform locally? Do you have some specific code we can look at?

avatar image Bunny83 · Jul 23, 2013 at 04:25 PM 0
Share

Exactly, what kind of transformations? Also your last sentence makes no sense. You don't "use" a Vector3 to move an object. The Vector3 describes the position of the object. So when it should change it's position, you have to change the Vector3.

Please add more details because this question isn't specific at all. Otherwise we have to close the question.

avatar image username707 · Jul 23, 2013 at 05:15 PM 0
Share

To clarify things imagine this

 for(int i =0; i < arrayGameObject.Length; i++){
     cachedTransform = arrayGameObject[i].transform;
 
     //multiple  cachedTransform.position, cachedTransform.rotation calls,
     //Vector3 transformations
 }

Where arrayGameObject is GameObject[] and can be about 500+ size

avatar image username707 · Jul 23, 2013 at 05:32 PM 0
Share

To clarify things imagine this

 for(int i =0; i < arrayGameObject.Length; i++){
 cachedTransform = arrayGameObject[i].transform;
 //multiple cachedTransform.position, cachedTransform.rotation calls,
 //Vector3 transformations
 }

Where arrayGameObject is GameObject[] and can be about 500+ size

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by robertbu · Jul 23, 2013 at 05:52 PM

The issue here is unlikely to be related to the transform. You can make your code a bit more efficient by using an array of Transforms rather than an array of GameObjects. You can always get to the game object using Transform.gameObject. I've read that under the hood, Unity does a GetComponent() call to get the Transform, so it is not just the indirection that is a potential slowdown.

But with that said, this code isn't that slow. If you want to test it, populate your list with empty game objects or with game object with their renderer disabled. Run your movement code, increasing the size of your array until you see a FPS drop. My guess is that you will hit the wall with memory before this code becomes and issue, and even 10,000 empty or non-rendered objects will not slow down the FPS. But creating that many object will cause a slowdown, so take any readings while objects are not being created. If you are concerned, run the test. Make sure you run it in a build rather than in the editor, since there are slowdowns in the editor due to large numbers of objects that don't occur in a real build. And you can use this script to show FPS:

http://wiki.unity3d.com/index.php?title=FramesPerSecond

I predict that any issue with 500 game objects will have a lot more to do with rendering than how you move them. Performance will depend mesh complexity, how the game objects batch and the efficiency of the shader. More info on batching:

http://docs.unity3d.com/Documentation/Manual/DrawCallBatching.html

Comment
Add comment · Show 7 · 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 username707 · Jul 24, 2013 at 05:46 AM 0
Share

Array of Transforms ins$$anonymous$$d of GameObjects helped a lot!

avatar image username707 · Jul 24, 2013 at 05:54 AM 0
Share

Also helps reducing timeScale and polycount of models

avatar image username707 · Jul 24, 2013 at 05:55 AM 0
Share

And i hope to optimize code for cycle. for now its feasible 35 fps per 300 units on A7 device

avatar image robertbu · Jul 24, 2013 at 09:13 AM 2
Share

As you can guess from my answer, I'm surprised that using Transforms rather than GameObjects made a substantial difference. I expected some, but not as much as "helped a lot!"

avatar image chris_taylor · Jul 24, 2013 at 09:31 AM 1
Share

Just to add onto this, you could also add it into a coroutine and only do X amount of transforms a frame.

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

18 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

Related Questions

solution for long simple animation? 1 Answer

Performance when having Update functions in many gameObjects ? 1 Answer

MonoBehaviour Update() performance vs handling updates in a single UpdateManager script 0 Answers

Lerping Issue 1 Answer

Vector2 vs Vector3 performance? 2 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