Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Unity 5 to Unity 2021 android performance tips

Discussion in 'Android' started by UnityLighting, Oct 23, 2016.

  1. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    31
    Dunno, if this forum is still up...:(
    When I try to run my game with resolution 1280 x720 on my phone (its native resolution is 1600 x 720) it looks stretched from side...
    Is it possible to run my game on every device with resolution of 1280 x 720 without having stretching issue?
    Bcuz when the game runs on 1600x720 or on native resolution it lags a bit.
    See the attached pic:
    [Eng isnt my primary lang, so dont bash for it!] :)
     
  2. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,199
    try:
    Code (CSharp):
    1.  
    2.  
    3. if(PlayerPrefs.GetInt("FirstRun") != 1)
    4. {
    5.     PlayerPrefs.SetInt("aspectX" ,Screen.GetResolution.x);
    6.     PlayerPrefs.SetInt("aspectY" ,Screen.GetResolution.y);
    7.     PlayerPrefs.SetInt("FirstRun") ,1);
    8. }
    9.  
    10. Screen.SetResolution (1280, 720, true);
    11. Camera.main.aspect  = PlayerPrefs.GetInt("aspectX") / PlayerPrefs.GetInt("aspectY");
    12.  
     
    AshwinTheGammer likes this.
  3. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    31
    since get resolution is deprecated. so, im trying to know that is x = height or width of the device?
    im doing like this

    Code (CSharp):
    1. int current_res_x = PlayerPrefs.GetInt("aspectX", Screen.currentResolution.height);
    2. int current_res_y = PlayerPrefs.GetInt("aspectY", Screen.currentResolution.width);
     
  4. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,199
    x = width
    y = height
     
    AshwinTheGammer likes this.
  5. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    31
    How would merging normal map, AO, roughness would increase the performance on android device... could u explain?
     
  6. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    31
  7. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,199
    I have a material baker tutorial








     
    AshwinTheGammer likes this.
  8. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,199
    Update 2021 optimization tips (all in one document) attached to this :
     

    Attached Files:

    AshwinTheGammer and MintIsHere like this.
  9. MintIsHere

    MintIsHere

    Joined:
    Nov 20, 2019
    Posts:
    34
    thanks man
     
  10. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    31
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. using UnityEngine.Rendering;
    6.  
    7. public class TargetFrameLimiter : MonoBehaviour
    8. {
    9.     int FirstRun = 0;
    10.     void Start()
    11.     {
    12.         string names = SceneManager.GetActiveScene().name;
    13.  
    14. #if UNITY_EDITOR
    15.         if (names == SceneManager.GetActiveScene().name)
    16.         {
    17.             QualitySettings.vSyncCount = 0;
    18.             FirstRun = PlayerPrefs.GetInt("FirstRun");
    19.             if (FirstRun != 1)
    20.             {
    21.                 PlayerPrefs.SetInt("aspectX", Screen.currentResolution.width);
    22.                 PlayerPrefs.SetInt("aspectY", Screen.currentResolution.height);
    23.                 PlayerPrefs.SetInt("FirstRun", 1);
    24.             }
    25.  
    26.             Screen.SetResolution(1280, 720, true);
    27.             Camera.main.aspect = PlayerPrefs.GetInt("aspectX") / PlayerPrefs.GetInt("aspectY");   [B][I][U]//Line 26[/U][/I][/B]
    28.             Application.targetFrameRate = 60;
    29.  
    30.  
    31.         }
    32. #endif
    33.     }
    34. }
    Here is my code: and it showed me this error
    NullReferenceException: Object reference not set to an instance of an object
    TargetFrameLimiter.Start () (at Assets/Scripts/TargetFrameLimiter.cs:26)

    i dont have any clue, why is it happening :(
     
  11. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,199
    You must have a camera with "Main Camera" tag in your scene
     
    AshwinTheGammer likes this.
  12. sas67uss

    sas67uss

    Joined:
    Feb 8, 2020
    Posts:
    71
    Hi
    Do you try and test URP performance on mobile versus built-in pipeline with mobile shaders ?
     
  13. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,199
    not yet
    On a simple test both had 60fps on my phone
     
  14. sas67uss

    sas67uss

    Joined:
    Feb 8, 2020
    Posts:
    71
    I hope perhaps combining URP and your tips gets better results than mobile shaders!
     
  15. mukki014

    mukki014

    Joined:
    Jul 30, 2017
    Posts:
    161
    My experience with URP on powerVR device wasn't as I was having graphical glitches because I used post processing comes with URP. On the other hand same scene works well in adreno devices. So I switched back to built in render pipeline as it gives more options for rendering and image effects/ shaders.
     
  16. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    31
    I had tried what you'd said...but it just zooms in the screen. Here's how it looks in Play Mode(CAPTURE1.JPG, CAPTURE2.JPG)
    and CAPTURE3.JPG is default one.
    Any solution to this?
     

    Attached Files:

  17. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,199
    try this option:
    Untitled.jpg
     
    AshwinTheGammer likes this.
  18. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    31
    I did try that but it didn't work. Well, np. I'd try that again. and report back to u
     
  19. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,199
    finding proper aspect ratio for different devices is not simple
    I just write my idea (script) . I didn't tested the above script
     
  20. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    31
    This shader package isnt compatible with URP
     
  21. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,199
    no
     
unityunity