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 anonymous_16296 · Apr 10, 2016 at 04:45 PM · androidoptimizationphysics2dprofilerspikes

Physics2D lag on increased timescale

I have been working on an infinite runner kind of game in which i am trying to implement a speedup powerup kind of thing . Something that will allow me to boost through the levels at a high speed

I did this by increasing the timescale value to 5.0 but doing that causes physics lag spikes in the profiler for mid end phones(LG - NEXUS 4)

alt text

i have quite a few colliers in the scene which i cannot reduce as the game kind of requires that collision accuracy

The impact is kind of unexpected as the areas with low physics2d actually have more active bodies at that time

is there anything i can do to reduce this , or any other way i can achieve this ?

Unity Version - 5.0.2f1

screenshot-10.png (146.3 kB)
Comment
Add comment · Show 10
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 Oribow · Apr 10, 2016 at 06:19 PM 0
Share

You could just let the player move faster, without changing the timescale.

avatar image anonymous_16296 Oribow · Apr 10, 2016 at 06:44 PM 0
Share

i cant cause its not actually the player that moves down, its a sequence of randomly generated levels that move upward . and i cant seem to change their velocity because for some reason doing so causes them to go out of alignment and makes them overlap each other

avatar image Oribow anonymous_16296 · Apr 10, 2016 at 06:48 PM 0
Share

Post the code for that. Then I could help you speed things up.

Show more comments
avatar image MelvMay ♦♦ · Apr 11, 2016 at 06:26 AM 0
Share

The 2D physics is reporting 0.7ms for the step time (Box2D update) but the CPU graph is showing 7.9ms for 'physics'. Double-check in the breakdown what this is and ensure that it's not 3D physics doing something odd (ignore the fact that you may not be using it).

Either way, the 2D physics is showing very little in the above image.

BTW: You'll get terrible accuracy when you increases the time-scale like that. Assu$$anonymous$$g the defaults, that'll be 50/5 = 10Hz physics updates.

avatar image anonymous_16296 MelvMay ♦♦ · Apr 11, 2016 at 08:31 AM 0
Share

i checked there's no mention of Physics in the profiler , even the physics profiler graphs shows straight zero lines in all the categories and i don't even want the collisions to be registered during this interval , its just a speed dash ignoring all the collision is there a way i can temporarily disable physics ?

avatar image MelvMay ♦♦ anonymous_16296 · Apr 11, 2016 at 09:10 AM 0
Share

You say 'Physics' but there's two sections for physics for both 2D and 3D . The graph above certainly isn't zero. If the spike is related to physics, there'll be a breakdown of what is causing that in the profiler.

You should see a complete breakdown in the CPU area.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Oribow · Apr 10, 2016 at 09:41 PM

This scripts should be much more efficient. It controlls the entire movement and spawning of the level pieces.

 using UnityEngine;
 
 //Author: Oribow
 public class EndlessRunner : MonoBehaviour {
 
     //Controlls the speed
     public float runningSpeed = 1;
     //Controlls the direction
     public Vector3 runningDir = Vector3.left;
     //Just for testing purpose
     public GameObject prefab;
    
     //Controlls the y height of the spawned objects
     public Transform levelSpawnPos;
 
     private float outOfCameraLeft;
     private float outOfCameraRight;
     private Camera mainCamera;
     private LevelPiece firstPiece;
     private LevelPiece lastPiece;
 
     void Start()
     {
         mainCamera = Camera.main;
         outOfCameraLeft = mainCamera.ScreenToWorldPoint(new Vector3(mainCamera.rect.xMin * Screen.width,0,0)).x;
         outOfCameraRight = mainCamera.ScreenToWorldPoint(new Vector3(mainCamera.rect.xMax * Screen.width, 0,0)).x;
         SpawnTheScreenFull();
     }
 
     void Update()
     {
         if (firstPiece.PosHorizontalRight < outOfCameraLeft)
         {
             LevelPiece oldPiece = firstPiece;
             Destroy(oldPiece.piece);
             SpawnTheScreenFull();
              firstPiece = oldPiece.next;
             oldPiece.next = null;
             
         }
         UpdateLevePiecePositions();
     }
 
     public void SpawnTheScreenFull()
     {
         Vector3 position = levelSpawnPos.position;
         if (lastPiece == null)
             position.x = outOfCameraLeft;
         else
             position.x = lastPiece.PosHorizontalRight;
         
         while (position.x < outOfCameraRight)
         {
             LevelPiece currentLevelPiece = new LevelPiece(GetRandomLevelPiece());
             position.x += currentLevelPiece.HalfWidth;
             currentLevelPiece.piece = Instantiate(currentLevelPiece.piece, position, Quaternion.identity) as GameObject;
             AddNewLevelPiece(currentLevelPiece);
             position.x += currentLevelPiece.HalfWidth;
         }
     }
 
     public GameObject GetRandomLevelPiece()
     {
         //Insert your random selector here
         return prefab;
     }
 
     public void AddNewLevelPiece(LevelPiece newPiece)
     {
         if (lastPiece == null)
         {
             lastPiece = newPiece;
             firstPiece = newPiece;
         }
         else
         {
             lastPiece.next = newPiece;
             lastPiece = newPiece;
         }
     }
 
     public void UpdateLevePiecePositions()
     {
         LevelPiece currentPiece = firstPiece;
         while (currentPiece != null)
         {
             currentPiece.piece.transform.Translate(runningDir * runningSpeed * Time.deltaTime);
             currentPiece = currentPiece.next;
         }
     }
 }

LevelPiece:

 using UnityEngine;
 
 //Author: Oribow
 public class LevelPiece
 {
     public LevelPiece next;
     public GameObject piece;
     private Sprite sprite;
     public float PosHorizontalRight { get { return piece.transform.position.x + HalfWidth; } }
     public float PosHorizontalLeft { get { return piece.transform.position.x - HalfWidth; } }
 
     public LevelPiece(GameObject piece)
     {
         this.piece = piece;
         sprite = piece.GetComponent<SpriteRenderer>().sprite;
         next = null;
     }
 
     public float HalfWidth {
         get { return (piece.transform.localScale.x * sprite.bounds.size.x) / 2; }
     }
 
     public float Width
     {
         get { return piece.transform.localScale.x * sprite.bounds.size.x; }
     }
 }
Comment
Add comment · Show 5 · 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 anonymous_16296 · Apr 14, 2016 at 10:27 AM 0
Share

sorry for late reply i got a bit busy with life . @Oribow i tried your code , a bit modified version of it as my game is going up rather than left, and yes the physics2d performance was reduced by a lot :D but now i have some device.present and (surprisingly) physX stutters in the graphics even though it shows in the profiler there are zero bodies in the physics 3d area and i am not even using 3D physics @$$anonymous$$elv$$anonymous$$ay you were right I don't know why that is happening .
alt text alt text

screenshot-14.png (216.2 kB)
screenshot-16.png (109.3 kB)
avatar image MelvMay ♦♦ anonymous_16296 · Apr 14, 2016 at 10:39 AM 0
Share

I just spoke to the 3D guys and various fixes are on the way for the case where 'Physics.Processing' is occuring when there are no 3D physics objects in the scene. I believe one of the fixes relates to thread-stalls and the other is simply where the physics update is not called at all if there are no physics objects.

avatar image anonymous_16296 anonymous_16296 · Apr 14, 2016 at 12:23 PM 0
Share

So i guess i can just wait on that then :/ . but is there anything i can do to reduce the device.present impact cause it is also pretty considerable

avatar image MelvMay ♦♦ anonymous_16296 · Apr 14, 2016 at 01:02 PM 0
Share

It's typically VSync related but it's certainly the graphics driver.

Did a quick Google search: http://forum.unity3d.com/threads/device-present-in-profiler-what-the-deal.86312/

Show more comments

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

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

Physics2D.FixedUpdate and Device.Present lag spikes in profiler 0 Answers

Need help profiling first game. Huge GPU spikes? 1 Answer

Draw Calls are still HIGH? 0 Answers

Device.present causing unexplainable slowdown 3 Answers

Some question about making Android game. 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