- Home /
Retina specific framerate drop on specific function
I'm working on a game that long story short involves a bunch of cubes flying around. Your player can destroy these cubes at certain intervals, causing them to "blow up", which is basically just instantiating an empty object containing 8 cube objects, (about 150tris each with mobile textures) they don't contain scripts only colliders and rigidbodies.
When running the game on a 1st gen iPad Mini the problem never happens and the framerate stays solid at 60fps. Only on the retina Mini will it bog down to 30fps if you blow up three or more cubes in close succession (0.5-1 second gap) and for the love of god I cannot figure out why. Here is the method that is called when the collision happens. Please let me know if I have something clearly wrong that could be causing such an issue on a current gen retina device.
Additionally, if you'd like more info/example I'd be happy to provide it. Thank you.
function enemyClusterExplode()
{
audioMan.PlayCubeExplode(); //play sfx
Destroy(this.gameObject);
//instantiate at pos/rot of enemy cube
var cubeCluster : Rigidbody = Instantiate(enemyCluster, transform.position, transform.rotation);
cubeCluster.transform.localScale = gameObject.transform.localScale;
//give the cluster an explosive force
var explosionPos : Vector3 = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (explosionPos, explodeRadius);
for (var hit : Collider in colliders)
{
if(!hit)
continue;
if(hit.rigidbody)
hit.rigidbody.AddExplosionForce(explodePower, explosionPos, explodeRadius, 0.3);
}
}
UPDATE: I changed the instantiate call above to nested objects that simply get turned on/off when collision happens. Still getting the same issue when you hit 3+ cubes close together in time. I'll have to shift my attention elsewhere as this doesn't look like the problem.
At time of slowdown the stats are showing about 6.5k tris in the scene and between 20-35 draw calls happening. I'm still absolutely confused why this is only occurring on retina hardware…
function enemyClusterExplode()
{
audioMan.PlayCubeExplode();
cubeCluster.SetActive(true);
cubeCluster.transform.parent = null;
//give the cluster an explosive force
var explosionPos : Vector3 = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (explosionPos, explodeRadius);
for (var hit : Collider in colliders)
{
if(!hit)
continue;
if(hit.rigidbody)
hit.rigidbody.AddExplosionForce(explodePower, explosionPos, explodeRadius, 0.3);
}
enemySpawnRef.maxRespawnTime -= 0.009f;
enemySpawnRef.launchSpeed += 0.01f;
this.gameObject.SetActive(false);
}
First of all you need to stop Destroying and instanting object at runtime
Ins$$anonymous$$d
for faster solution
Create a num object(lets say up to 10) during start and just enable and desable it at runtime
ins$$anonymous$$d of instantiating ti just set it position to the target position(transform.position in yuor case ) and enable the object and create a yield function to wait for few seconds the n disable the object
I agree that instantiating and destroying isn't the most efficient, but why would older, slower hardware NOT have a problem with this, while the newest hardware does?
Answer by BrinkHouseGames · Dec 07, 2013 at 08:46 PM
I figured out the problem. I had in quality settings the Anti-Aliasing set to 4x for a cleaner look on non-retina devices. I added a bit of code to check the resolution of the device and set the AA accordingly and that fixed the lag.
Your answer
Follow this Question
Related Questions
Overlapping instantiation issues. Help? 1 Answer
Instantiated child doesn't move along with the parent in case of low frame rates 0 Answers
Instantiate loading very slowly 3 Answers
How do I switch from Character player to Airship Vehicle using triggers? 0 Answers
Help with my On_Bullet please 1 Answer