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 /
  • Help Room /
avatar image
0
Question by seaders · Sep 03, 2015 at 03:49 PM · androidcamera-movementstutter

Bad stutter on Android (specifically Samsung Galaxy S4), with very simple code

Full project: https://github.com/SixMinute/UnitySamsungS4Stutter

InGameCameraController.cs:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class InGameCameraController : MonoBehaviour 
 {
     public Transform ballTrans;
     public Rigidbody2D rb;
 
     Vector3 _CarPos;
 
     Vector3 _CameraPrevPos;
 
     private Camera _Camera;
     float _OrthographicSizeStart;
 
     public static float SMOOTH_CAMERA_FOLLOW_SPEED = 10f;
 
     private float _ZoomExtra;
 
     private Vector3 _CameraVelocity = Vector3.zero;
 
     void Awake () 
     {
         _Camera = GetComponent<Camera>();
         Application.targetFrameRate = -1;
     }
 
     
     public void LateUpdate()
     {
         _CarPos = getCarPosition();
         updateCameraSmoothFollow();
     }
     
     public float dampTime = 0.3f;
     private Vector3 velocity = Vector3.zero;
     public Transform target;
     
 void updateCameraSmoothFollow () 
 {
     if (target)    
     {
             Vector3 point = _Camera.WorldToViewportPoint(target.position);
             Vector3 delta = target.position - _Camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z)); //(new Vector3(0.5, 0.5, point.z));
             Vector3 destination = transform.position + delta;
             transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
         }
     }
     
     bool updateCamera()
     {
         return true;
     }
     
     Vector3 getCarPosition()
     {
         return ballTrans.position;
     }
 
     Vector2 getCarVelocity()
     {
         return rb.velocity;
     }
 }

MoveCamera.cs

 using UnityEngine;
 using System.Collections;
 
 public class MoveCamera : MonoBehaviour {
     
     public float _MaxY;
     public float _MinY;
     private bool _DirUp;
     private float _CurrentY;
     private Vector3 _LocalVector;
     
     void Start () 
     {
         _CurrentY = _MaxY;
         _DirUp = false;
         _LocalVector = new Vector3();
     }
     
     void Update () 
     {
         float distanceThisFrame = 10.0f * Time.deltaTime;
         if(_DirUp)
         {
             _CurrentY += distanceThisFrame;
             
             if(_CurrentY > _MaxY)
             {
                 _CurrentY = _MaxY;
                 _DirUp = false;
             }
         }
         else
         {
             _CurrentY -= distanceThisFrame;
             
             if(_CurrentY < _MinY)
             {
                 _CurrentY = _MinY;
                 _DirUp = true;
             }
         }
 
         _LocalVector.Set(transform.position.x, _CurrentY, transform.position.z);
         transform.position = _LocalVector;
     }
 }
 

SMRect.cs:

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class SMRect
 {
     public float minX;
     public float minY;
     public float maxX;
     public float maxY;
 
     public SMRect(float minX, float minY, float maxX, float maxY)
     {
         this.minX = minX;
         this.minY = minY;
         this.maxX = maxX;
         this.maxY = maxY;
     }
 
     public static SMRect fromBounds(Bounds bounds)
     {
         return new SMRect(bounds.min.x, bounds.min.y ,bounds.max.x, bounds.max.y);
     }
 }


It's an incredibly simple project, with nearly nothing happening other than a few camera changes, but stutters every 5-10 seconds on more than a few Android devices, and incredibly evident on the Samsung Galaxy S4.

This is obviously just a sample project, but it's happening in our main project, too and it's hammering our performance no matter how many other optimisations we do. So long as this stutter continues our game, and I'm assuming many other Unity games on Android, massively suffer.

There's two bug reports we've submitted about this, 702035, where we weren't able to nail down exactly what caused the stutter, nor exactly which devices show it clearly, but our newest one, from yesterday, 724610, is the clearest example of this problem we've been able to find. The bug hasn't yet, as far as I know, popped it's head up on the issue tracker (I'll update this thread when it does), but I wanted to put this here as well, in case others also get hit with this.

I'm assuming this is an internal Unity problem, but just in case others have suggestions, or potential solutions for this, they'd be really great to see.

Comment
Add comment · Show 2
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 hexagonius · Sep 03, 2015 at 09:09 PM 0
Share

have you checked the profiler for spikes? try deep profiling if there is and you want to know more exactly.

avatar image seaders · Sep 03, 2015 at 11:06 PM 0
Share

Yup, have profiled and found nothing like a smoking gun. Delved into quite a few Android things that popped up in Logcat, but nothing pointed to anything. One way or another, with such small code, you'd have to consider any spike in performance something that Unity must look at themselves, probably.

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

29 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 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

Touch camera movement isn't smooth on Android 0 Answers

Lags while camera movement (gfx.waitforpresent) 0 Answers

How to move the camera in VR mode? 2 Answers

Unity Touch Pan Orthographic camera, 0 Answers

Android game stutters (ruckelt) on splash screen and in game 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