Issue
I'm working on simple 2d project, sprites run from top to bottom and on standard phones (60hz) everything look smooth, but on s20+ (exynos 990 version) with 120hz on, sprites start gently tug, jumps, loosing smoothness. when i turn off 120hz refresh rate, game work perfect. at first move was based on while loop with yield return new WaitForEndOfFrame();
and that was causing another problem. if it was based on frames whole move was 2x faster, and game was unplayable.
so i decided to build movement on void Update()
, and turn on vSync, that solve 2x speed problem but it doesn't help with smooth lose,
I was trying to limit frame rate to 60 by Application.targetFrameRate = 60;
with vSync on 0, same result.
so my question is: Is there any possibility to do something with it? Can i somehow tell phone to turn off 120hz refresh for time when my app is running? or maybe there is some option in unity settings that i don't know about, which can solve my misery. I'm really on the edge of mental breakdown now.
Solution
Try this (to turn on 120hz display mode):
Create file "MainActivity.java" in Assets folder.
Open this file and paste code:
package com.*YOUR COMPANY NAME*.*YOUR PRODUCT NAME*;
import com.unity3d.player.UnityPlayerActivity;
import android.os.Bundle;
import android.os.Build;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends UnityPlayerActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Window w = getWindow();
WindowManager.LayoutParams p = w.getAttributes();
Display.Mode[] modes = getDisplay().getSupportedModes();
//find display mode with max hz
int maxMode = 0;
float maxHZ = 60f;
for(Display.Mode m:modes) {
if (maxHZ < m.getRefreshRate()) {
maxHZ = m.getRefreshRate();
maxMode = m.getModeId();
}
}
p.preferredDisplayModeId = maxMode;
w.setAttributes(p);
}
}
}
Change
*YOUR COMPANY NAME*
and*YOUR PRODUCT NAME*
to Company Name and Product Name from Project Settings -> Player.Go to Project Settings -> Player -> Publishing Settings. Tick "Custom Main Manifest".
Open file "AndroidManifest.xml" in "Assets\Plugins\Android".
Change android:name=
com.unity3d.player.UnityPlayerActivity
to android:name=com.*YOUR COMPANY NAME*.*YOUR PRODUCT NAME*.MainActivity
.Be sure to call
Application.targetFrameRate = Screen.currentResolution.refreshRate;
in any script!
UPDATE: FIXED BUG IN ANDROID 12.
https://forum.unity.com/threads/set-screen-refresh-rate-on-android-11.997247/
Answered By - ComRSMaster
Answer Checked By - Terry (JavaFixing Volunteer)