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 Andrey Rykov · Nov 08, 2013 at 03:46 PM · transformoptimization

How can I optimize this script?

I need to optimize this script, because when I move the object it uses nearly 40% of my CPU (You can see it in the screenshot) and it reduces the FPS from 80 to 40.

alt text

Here is my code:

 using UnityEngine;
 using System.Collections;
 
 public class JointFree : MonoBehaviour
 {
     
     private GameObject telega;
     private GameObject most;
     // Use this for initialization
     void Start ()
     {
         telega = GameObject.Find ("cran_i_cabina/most/telega");
         most = GameObject.Find ("cran_i_cabina/most");
     }
     
     // Update is called once per frame
     void Update ()
     {        
         var position = gameObject.transform.position;
         var rotation = gameObject.transform.eulerAngles;
         
         Debug.Log (transform.eulerAngles.x > 0.0001f || transform.eulerAngles.z > 0.0001f);
         if (Mathf.Abs(transform.eulerAngles.x) > 0.000001f || Mathf.Abs(transform.eulerAngles.z) > 0.000001f) {
             gameObject.transform.eulerAngles = new Vector3 (0.0f, rotation.y, 0.0f);
         }
         
         if (Mathf.Abs(telega.gameObject.transform.position.x - position.x + 0.103f) > 0.0001f || Mathf.Abs(telega.gameObject.transform.position.y - 10.86f) > 0.0001f || Mathf.Abs(telega.gameObject.transform.position.z - position.z + 0.11f) > 0.0001f) {
             telega.gameObject.transform.position = new Vector3 (position.x - 0.103f, 10.86f, position.z - 0.11f);
         }
 
         if (Mathf.Abs(telega.transform.eulerAngles.x) > 0.0001f || Mathf.Abs(telega.transform.eulerAngles.y) > 0.0001f || Mathf.Abs(telega.transform.eulerAngles.z) > 0.0001f) {
             telega.gameObject.transform.eulerAngles = Vector3.zero;
         }
         
         if (Mathf.Abs(most.gameObject.transform.position.x - position.x - 2.133f) > 0.0001f || Mathf.Abs(most.gameObject.transform.position.y - 10.8535f) > 0.0001f || Mathf.Abs(most.gameObject.transform.position.z) > 0.0001f) {
             most.gameObject.transform.position = new Vector3 (position.x + 2.133f, 10.8535f, 0.0f);
         }
         
         if (Mathf.Abs(most.transform.eulerAngles.x) > 0.0001f || Mathf.Abs(most.transform.eulerAngles.y) > 0.0001f || Mathf.Abs(most.transform.eulerAngles.z) > 0.0001f) {
             most.gameObject.transform.eulerAngles = Vector3.zero;
         }
     }
 }
 


profiler.png (74.3 kB)
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

1 Reply

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

Answer by Dave-Carlile · Nov 08, 2013 at 03:47 PM

Remove the call to Debug.Log. Executing those every update is bad.

Comment
Add comment · Show 1 · 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 Andrey Rykov · Nov 09, 2013 at 08:37 AM 0
Share

Thank You. It helped a little bit and now FPS reduces from 80fps to 55 fps.

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How do I efficiently maintain a constantly-changing list without triggering GC? 2 Answers

Programatically driven particles 1 Answer

The nested type `TransformDirection' does not exist in the type `UnityEngine.Transform' 1 Answer

Set controller to active script - how do I transform him to the correct position? 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