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 17, 2015 at 07:01 PM · networkingfpslow fpsping

Very Low FPS

Hi!

I have very very low fps in my game. My creatures have behaviour script attached and if i remove this script or at least Update() functions fps will become normal.

So suggest me please something to fix in my code to make fps higher!

   // Update is called once per frame
     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);
             }
         }
     }

And WayPoint movement:

   public void WaypointMovement()
     {
         if (networkView.isMine)
         {
             wayPointMovementTime += Time.deltaTime; //current?
 
             if (_flagWayPoint1)
             {
                 wayPointRot = Random.Range(0, 360);
 
                 transform.eulerAngles = new Vector3(0, wayPointRot, 0);
                 _wayPointDir = transform.TransformDirection(Vector3.forward); //Skipped
                 _timeRadius = Random.Range(0.1f * wayPointMaxRadius, wayPointMaxRadius);
 
                 /*if (networkView.isMine)
                 {
                     networkView.RPC("AdjustTheTimeRadius", RPCMode.AllBuffered, (float)Random.Range(0.1f * wayPointMaxRadius, wayPointMaxRadius));
                 }*/
 
                 _flagWayPoint1 = false;
             }
 
             if (!_flagWayPoint1 && wayPointMovementTime < _timeRadius)
             {
                 _flagWayPoint2 = true; 
                 _wayPointDir.y -= 20.0f * Time.deltaTime; //gravity
                 _controller.Move(_wayPointDir * Time.deltaTime * wanderingSpeed);
             }
 
             else
             {
                 if (_flagWayPoint2)
                 {
                     StartCoroutine(DoTheWay());
                     _flagWayPoint2 = false;
                 }
                 //wayPointMovementTime = 0;
             }
         }
 
         else
         {
             this.gameObject.transform.position = wayPointClientPos;
             this.gameObject.transform.rotation = wayPointClientRot;
         }
     }
 
     IEnumerator DoTheWay()
     {
         _nextGoTime = Random.Range(2f, 9f);
         /*if (networkView.isMine)
         {
             networkView.RPC("AdjustTheTimeStand", RPCMode.AllBuffered, (float)Random.Range(2f, 9f));
         }*/
         yield return new WaitForSeconds(_nextGoTime);
         _flagWayPoint1 = true;
         wayPointMovementTime = 0;
     }



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
2

Answer by Chris333 · Jan 18, 2015 at 05:36 PM

Hi,

you could begin by removing the Find methods in the LateUpdate() and FixedUpdate() methods, because these methods are traversing the complete scene hierarchy each time if they get called. You call them every frame more than ones, so that could realy be the problem.

In the unity api documentation it says: "For performance reasons it is recommended to not use this function every frame Instead cache the result in a member variable at startup or use GameObject.FindWithTag." http://docs.unity3d.com/ScriptReference/GameObject.Find.html

Create a public variable and attach the MainCamera to it via the inspector or use the Find-method only in the Start() method to get the reference to your MainCamera.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Adding objects on player models in a multiplayer game 0 Answers

Networked FPS raycast shoot inaccuracy 1 Answer

Directional Light Causing Low FPS 1 Answer

How do I change the GUI of the network manager HUD? 1 Answer

Problems With Networking. 0 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