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 epicVoodoo · Jan 12, 2015 at 04:42 PM · fpsupdatelagslatencyping

Very Low fps.

Hi there!

I have script wich realizes creatures behaviour. If there are 3 or more monsters with this scripts FPS will become very low. If i delete all Update methods (Update(), FixedUpdate(), LateUpdate()) fps rises. So can u advice me please how to rewrite my code to archieve normal fps in my game.

     void Update()
     {
         if (gameObject.transform.rotation != spawnRotation)
         {
             //this.gameObject.transform.rotation = Quaternion.AngleAxis(rotOffset, Vector3.up);
         }
 
         if (networkView.isMine)
         {
             if (target != null && isAlive && startAggro && target.GetComponent<Player>().isAlive)
             {
                 Attack(target);
             }
         }
 
         Die();
 
         curHP = Mathf.Clamp(curHP, 0, maxHP);
 
         if (isAlive)
         {
             if (checkForReAggro && attackersList.Count > 1)
             {
                 StartCoroutine(AggroDontHitRecovery(attackersList.Last()));
 
                 if (toggleToOtherTarget)
                 {
                     AdjustTarget(attackersList.Last());
                     toggleToOtherTarget = false;
                 }
             }
 
             if (_bUpdateRestoreHpAfterRunaway)
             {
                 StartCoroutine(WaitAfterRunAwayForRestore());
                 _bUpdateRestoreHpAfterRunaway = false;
             }
 
             else
             {
                 _bUpdateRestoreHpAfterRunaway = false;
             }
         }
     }
 
     void LateUpdate()
     {
         if (_allowWaypointMove && isAlive && GameObject.Find("MainCamera").GetComponent<Server>().connected) //!It used to be in FixedUpdate 11.01.15 / 0:12:00
         {
             WaypointMovement();
         }
     }
 
     void FixedUpdate()
     {
 
         if (isAlive)
         {
             Aggro();
         }
 
         if (networkView.isMine)
         {
             networkView.RPC("AdjustThePos", RPCMode.AllBuffered, this.transform.position);
             networkView.RPC("AdjustTheRot", RPCMode.AllBuffered, this.transform.rotation);
         }
 
         if (GameObject.Find("MainCamera").GetComponent<Server>().connected && this.gameObject != null)
         {
             if (isAlive)
             {
                 networkView.RPC("AdjustSpeed", RPCMode.All, (transform.position - lastPos).magnitude);
                 networkView.RPC("SendFloat", RPCMode.All, "Speed", speed);
             }
         }
 
         if (target != null)
         {
             if (!(target.GetComponent<Player>().isAlive))
             {
                 networkView.RPC("KilledTarget", RPCMode.All);
             }
         }
     }

 
Comment
Add comment · Show 3
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 nu-assets · Jan 12, 2015 at 04:49 PM 1
Share

Perform following change at line 68:

Replace

 GameObject.Find("$$anonymous$$ainCamera")

with

 Camera.main

Linear search is always a bad idea when performed frequently.

avatar image epicVoodoo nu-assets · Jan 12, 2015 at 05:46 PM 0
Share

If i use assigning via the inspector, wont it be faster? 'cause i have a few main cameras

avatar image Tamaleh nu-assets · Jan 12, 2015 at 05:51 PM 0
Share

The Find method is very slow when there are a lot of objects in the scene and calling a camera directly will be much faster and use up less memory

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Android update math at higher hz? 2 Answers

How to handle fps for game? 1 Answer

Script lowering frame rate 3 Answers

How to create a dynamic map in hand of FPS like Far Cry 2 or Firewatch? 0 Answers

Updating at frameRate some fixedUpdated gameObject 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