Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 EvanesceExotica · Sep 08, 2015 at 04:41 AM · performancelagprofilerfixedupdate

PlayerController Script Causing Terrible Performance (Profiler says FixedUpdate: LogStringToConsole)

I've been using this player controller script since I first started working on my game, and it's never given me issues until now. The profiler says "PlayerController.FixedUpdate() > LogStringToConsole" is taking up about 96.3% of CPU usage--at least that's what I think it means.

Here is the script:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour
 {
 
     public float maxSpeed = 10f;
     public float hold;
     public bool facingRight = true;
     public bool cantMove;
 
     Animator anim;
 
     public bool grounded = false;
     
     public Transform groundCheck;
     float groundRadius = 0.2f;
     public LayerMask whatIsGround;
     public float move;
     public float jumpForce = 700f;
   
     void Start()
     {
         anim = GetComponent<Animator>();
         hold = maxSpeed;
 
     }
 
   
     void FixedUpdate()
     {
         
         grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
         anim.SetBool("Ground", grounded);
         anim.SetFloat("vSpeed", GetComponent<Rigidbody2D>().velocity.y);
 
         move = Input.GetAxis("Horizontal");
         anim.SetFloat("Speed", Mathf.Abs(move));
 
         GetComponent<Rigidbody2D>().velocity = new Vector2(move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);
 
         if (move > 0)
             FlipRight();
         else if (move < 0)
             FlipLeft();
     }
 
 
 
     void Update()
     {
         if (grounded && Input.GetKeyDown(KeyCode.Space))
         {
             anim.SetBool("Ground", false);
             GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpForce));
         }
         if (cantMove == true)
         {
             maxSpeed = 0;
         }
         else
         {
             maxSpeed = hold;
         }
     }
 
 
  
     public void FlipLeft()
     {
         Vector3 theScale = transform.localScale;
         theScale.x = -Mathf.Abs(theScale.x);
         transform.localScale = theScale;
         
 
     }
     public void FlipRight()
     {
         Vector3 theScale = transform.localScale;
         theScale.x = Mathf.Abs(theScale.x);
         transform.localScale = theScale;
 
     }
 }
 

I don't have a Debug.Log statement in this script, so I'm unsure of what the profiler means by "LogStringToConsole" in this instance. When I disable the PlayerController script, everything runs very smoothly. However, as I said, I've had this script in my game for a while, and everything has run fine before now.

Comment
Add comment · Show 1
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 FreeTinybop · Oct 06, 2016 at 12:34 AM 0
Share

I had a similar issue, was because lots of warnings were being logged, but I didn't notice since they weren't turned on in the console.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by getyour411 · Sep 08, 2015 at 04:44 AM

Probaby not directly related, but move those GetComponent for Rigidbody calls out of Fixed / Update - define those in Start

See this for additional info on that message (bottom of the thread) http://forum.unity3d.com/threads/profiler-showing-logstringtoconsole-what-is-that.237589/

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
avatar image
0

Answer by wibble82 · Sep 08, 2015 at 06:20 AM

Hey there.

Out of interest, what happens if you right click on the console and choose to 'show editor log'? It could be that one of your function calls is spamming the editor log but you just can't see it. Perhaps a warning about some of those animation parameters you're setting.

While there's clearly an actual issue here, it's worth noting you're doing some expensive stuff in fixed update there. If you haven't done so already, it might be worth looking at your time settings to make sure your fixed update time step is sensible. The default is crazy fast so you might be running that code far more often than you need to.

  • chris

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
avatar image
0

Answer by sandeepsmartest · Oct 06, 2016 at 04:51 AM

Check your console and try to solve all warnings.Scripts collects more GC if there are any print/debug.log statements or any other warnings.For Eg: if you try to settrigger("Xname") on some animator for which it doesn't have "Xname" parameter(condition) then it definitely throws you warning which results in Garbage Collection. FYI, String operations results in GC. Hope this may help you. Nsks.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Terrible Lag When Starting a Scene Which Eventually Resolves Itself... Graphics Card Issue or Unity? 1 Answer

Editor incredibly slow, weird profiler output. 1 Answer

Problem with profiler spikes caused by Semaphore.WaitForSignal 0 Answers

Performance issue: Camera.Renderer - Drawing - ... - Clear needs 50% CPU ??? 2 Answers

Unity Profiler - Loading.UpdatePreloading - Huge Lag Spikes 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