'Are there general methods to optimize fixedupdate or multiscene physics for an android build?
I have a game I am building for android. On Unity everything works and the apk file builds, but when I try to run the application on my Google pixel 6 it crashes after only being on for a couple seconds. I took a look at my unity profiler and I can tell a lot of this load is coming from my fixedupate function (see the large CPU spikes in image). Is there any general way to optimize fixed update or maybe slow down fixedupdate to be optimized for Android?
I am using fixedupdate to implement multiscene physics where each object has its own dedicated local physics scene within the scene.
private void FixedUpdate()
{
if (!sceneMainPhysics.IsValid())
return;
sceneMainPhysics.Simulate(Time.fixedDeltaTime);
}
void update()
{
//release velocity will always be a float
void simProjectiles(releaseVelocity)
}
{
if (!sceneMainPhysics.IsValid() || !scenePredictionPhysics.IsValid())
return;
Debug.Log("Time model is on");
int j = 0;
Debug.Log("Debugging positions for now");
ball = GameObject.CreatePrimitive(PrimitiveType.Cube);
ball.name = "whiteSphere";
SceneManager.MoveGameObjectToScene(ball, sceneMain);
ball.transform.localScale = new Vector3(.1f, .1f, .1f);
ball.AddComponent<Rigidbody>().velocity = releaseVelocity;
Material whiteMaterial = new Material(Shader.Find("Universal Render Pipeline/Lit"));
whiteMaterial.color = Color.white;
ball.GetComponent<MeshRenderer>().material = whiteMaterial;
ball.tag = "simCube";
ball.GetComponent<Collider>().enabled = ball.GetComponent<Collider>().enabled;
ball.transform.position = this.transform.position;
ball.GetComponent<Renderer>().enabled = false;
SceneManager.MoveGameObjectToScene(sim_target, scenePrediction);
foreach (Vector3 pos in this.positions)
{
GameObject predictionBall = GameObject.CreatePrimitive(PrimitiveType.Sphere);
SceneManager.MoveGameObjectToScene(predictionBall, scenePrediction);
predictionBall.AddComponent<Rigidbody>().velocity = releaseVelocity;
predictionBall.tag = "simObj";
predictionBall.name = "emptySphere";
predictionBall.transform.localScale = new Vector3(.01f, .01f, .01f);
predictionBall.GetComponent<Rigidbody>().collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
predictionBall.GetComponent<Collider>().enabled = predictionBall.GetComponent<Collider>().enabled;
predictionBall.GetComponent<Collider>().isTrigger = true;
predictionBall.GetComponent<Renderer>().enabled = false;
predictionBall.transform.position = pos;
Material redMaterial = new Material(Shader.Find("Universal Render Pipeline/Lit"));
redMaterial.color = Color.red;
//If object was destroyed by target collider
for (int i = 0; i < 20; i++)
{
scenePredictionPhysics.Simulate(Time.fixedDeltaTime);
GameObject pathMarkSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
pathMarkSphere.GetComponent<Collider>().isTrigger = true;
pathMarkSphere.transform.localScale = new Vector3(.01f, .01f, .01f);
pathMarkSphere.transform.position = predictionBall.transform.position;
pathMarkSphere.GetComponent<MeshRenderer>().material = redMaterial;
pathMarkSphere.tag = "simObj";
pathMarkSphere.GetComponent<Collider>().enabled = !pathMarkSphere.GetComponent<Collider>().enabled;
pathMarkSphere.GetComponent<Renderer>().enabled = false;
SceneManager.MoveGameObjectToScene(pathMarkSphere, scenePrediction);
singlePaths.Add(pathMarkSphere);
}
if (GlobalStates.simCollision == true)
{
yDistList.Add(Math.Abs(Target.dis_to_target));
}
GlobalStates.simCollision = false;
allPaths.Add(singlePaths);
singlePaths.Clear();
j++;
}
int optimalIndex = 0;
if (yDistList.Count() > 0)
{
float minVal = yDistList.Min();
optimalIndex = yDistList.IndexOf(minVal);
}
else
{
Debug.Log("yDistList is empty");
}
this.transform.position = positions[optimalIndex];
//Debug.Break();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

