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
1
Question by Tim De Cort · Oct 05, 2012 at 08:04 PM · transformperformancestatic variable

3 Questions (performance,static variabales,transfrom)

Hello Everybody,

I've been diving in to unity for the past month's and there are a few questions I have about some things I couldn't find clear answers online, mainly on scripting (maybe even scripting in general). btw I use C#.

1_# What is best performance-wise: Several gameobjects with the same script and individual inspector adjusted variables. And 1 Central script that governs movement of those gameobjects through static variables & limited use of getComponent (script) to acces the specific variables values.

OR

Every gameobject has his own version of the central script, repeating the same code serval times, but without(or less). static variables.

2# I understand that variables are generally faster, but I'm not sure on the border when it (or if it)becomes a burden on the script. So what if a variable or a specific number, (50 in the example below) has to be repeated 5 times in 5 seperate scripts? in each script int moveSpeed = 50

transform.Rotate(0,0,moveSpeed);

OR

transform.Rotate(0,0,50);

OR

One static variable that's accessed from a seperate script each time it's needed (and its needed often)

3# Why would you use Transform as a variable instead of specificying the gameObject in a variable and accessing the transform through there (i.e. the_gameobject.transfrom)?

Thanks in advance!

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
2

Answer by Graham-Dunnett · Oct 05, 2012 at 08:07 PM

These kind of issues will not really affect the performance of your game in any way. Most games are limited by the rate at which the graphics hardware can display the scene, or the rate at which animation data can be computed. It is possible to write a Unity game that is affected badly by script performance, but that's probably nothing you need to be concerned about.

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 Tim De Cort · Oct 05, 2012 at 08:43 PM 0
Share

So there's no performance backdraw in communicating between scripts and variable assignment at all?

avatar image Graham-Dunnett ♦♦ · Oct 05, 2012 at 08:59 PM 0
Share

Yes, there are costs. rudidev08 has given some good advice for #3. What I was trying to say is that these concerns are not likely to affect your final game. I doubt you'd be able to measure any performance difference for your #2, so you might want to design your code to make it easy to read and manage, rather than worry about how the compilers convert your code into byte code. So for #1, I'd have a single script and use the inspectors to adjust values for each game object. That would be easier to manage rather than having N variations of the same script.

avatar image
1

Answer by rudidev08 · Oct 05, 2012 at 08:43 PM

For #3, if you access transform via gameObject.transform, it performs GetComponent() behind the scenes, which can be slow if it's called too often, like in Update or loop. Assigning transform to the variable and using it with that variables skips constant calling of GetComponent.

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

11 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

Related Questions

Find GameObject Position(x,z) and rotation(y) 1 Answer

Calling gameobject.transform vs. just calling transform directly - Performance negligible? 1 Answer

Setting positions of cubes directly without using transform 1 Answer

Are .gameObject and .transform both using GetComponent() in the background? 1 Answer

Does moving a charactercontroller via it's transform hurt performance? 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