Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Some performance/scripting issues(objects jittering, while moving)

Discussion in 'Scripting' started by z37, Jan 2, 2015.

  1. z37

    z37

    Joined:
    Feb 13, 2014
    Posts:
    29
    Hello, guys!
    I seek for an advice to improve performance of my game. It's a 2d game, I use object pooling technic that is pretty much the same as given on live training tutorials. I have a prefab of a simple sprite image with a script attached:
    Code (CSharp):
    1. public class MoveDown : MonoBehaviour {
    2.  
    3. void Start () {
    4.         MovementDown (3.0f);
    5. }
    6.    
    7. void MovementDown (float speed){
    8.         iTween.MoveBy(gameObject, iTween.Hash("name", "ITweenMoveDown", "y", -10f, "speed", speed, "easetype", "linear", "oncomplete", "MovementDown", "oncompleteparams", speed));
    9. }
    10. }
    I use iTween here for other perpose, but the result is the same with simple Translate method in the Update function.
    Code (CSharp):
    1. void Update(){
    2.         transform.Translate(Vector3.down * Time.deltaTime * 3.0f);
    3. }
    So, I instantiate this prefabs in a special way randomly at the top of the screen by .SetActive(true) and give them needed position. When moving down, sprites have a little laggy trembling, it is not very noticeable on in the editor and devices with powerful CPU, but it become very laggy on low CPU.
    Every Sprite has collider2D attached to it and there are only two triggers to enable and disable this sprites.
    I tried also to move the camera only and but the laggy result is the same.

    What is the solution to move objects smooth?

    Looking forward to hearing from you!
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,683
    How many objects do you have in your pool? And what is low CPU? Some mobile units, if you are building for that are at this point, outdated.
     
  3. z37

    z37

    Joined:
    Feb 13, 2014
    Posts:
    29
    I have 16 objects in my pool. (i think that this amount is impossible to effect GPU and CPU performance, maybe the problem is in the wrong method of moving objects?) Low CPU device is Samsung galaxy Ace 2 (Dual Core 800MHz Processor).
    But it is also not so evenly smoot on Nexus 7 g2 and iPhone 4s, there can be a bit of laggy trembling seldom.
    Back to my Corona SDK practice, there was no such problem.
     
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,683
    Hm.
    There is most likely something else going on. I would need to see your scripts. Perhaps you are using update or OnGui incorrectly.
     
  5. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,887
    iTween and SetActive could cause things to "jerk". Also, cache the "transform" in Awake() before using it, like so: "t = transform", then t.Translate...

    Instead of SetActive, try disabling/enabling their renderer/collider/etc manually.
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    What's the actual frame rate you are getting? What does the profiler say?

    It sounds like this might not be a performance problem, but an error in your tween code. Something to consider anyway.
     
  7. z37

    z37

    Joined:
    Feb 13, 2014
    Posts:
    29
    I uploaded the part of my project. This lag is present even when i comment the 9 line in Instantiation.cs, so that only 3 objects move.

    Unfortunately, I don't have a pro license, so i can't use a profiler to check leaks. The actual frame rate in the editor is 60, on devices is the same 60, but on Nexus it goes pretty smooth, not to say about Galaxy Ace2 and editor.

    I would appreciate if someone could check my project.
     

    Attached Files:

  8. z37

    z37

    Joined:
    Feb 13, 2014
    Posts:
    29
    I tried to implement that behaviour, it seems like problem is not in SetActive and iTween(as i tried standart unity Translate() and also just to change transform.position manually)
     
  9. z37

    z37

    Joined:
    Feb 13, 2014
    Posts:
    29
    The problem is liklely to be in some script implementation, because even only one object has such lag/jitter, no fps drops.