Odd Build Performance

I am getting odd behavior when testing builds of my game on my test device.
#1- On reloading the scene, the whole game slows to a complete crawl. I poked around the forums and found some talk about memory leaks. I am using the “DetectLeaks.cs” script and according to that, my game is not leaking memory - the stats all remain the same no matter how many times I reload the level.
#2- Playing the game in the editor using UnityRemote, I need to tap the screen to instantiate some projectiles. This is the behavior that I want. But in the iPhone build, the projectiles are instantiating automatically without touching the screen at all. Here is the relevant code for #2:

function Update()
{
   var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
   var hit:RaycastHit;

   if(Physics.Raycast(ray, hit, 100)){
   		
      	if(hit.collider.name == "TriggerLeft"){
         		if (leftIsReloaded == true){
					var throwprojL : Rigidbody = Instantiate (proj, leftBox.transform.position, leftBox.transform.rotation);
					throwprojL.velocity = transform.TransformDirection(Vector3 (0,0,speed));
					Physics.IgnoreCollision(throwprojL.collider, body.collider);
					leftIsReloaded = false;
					ReloadLeft(); 
         		}
			}
      }
}

Any ideas what’s going on with either of these issues? Most of what I have tested performs in the iPhone build basically as it does in the editor - this is totally different.

you need to check for mousedown / touch if you want something to happen only when the screen is beeing touched.

there is no “passive” mouse state on the iphone.

Also to detect leaks, forget anything that runs within Unity as unity can only detect own stuff within the box, not leaks of the box itself. Use Instruments for example that comes with XCode

Hmm. I am a little confused.
Using the DetectLeaks script was recommended in this post which seemed to have a similar problem to my own:
http://forum.unity3d.com/viewtopic.php?t=17553
I have used Instruments to test leaks with projects made in xCode but couldn’t make much sense of the info Instruments provides. Is there anything clear written up on avoiding leaks when making iPhone apps in Unity? I could really use some guidelines to point me in the right direction as I never worried about leaks when using Unity in the past and didn’t even think I had to!

As to checking for mousedown / touch, as far as I could tell, the standard OnMouseDown function doesn’t work with Unity iPhone. Is that right?

And just as a general question, is it normal experience and to be expected to have things behave in the Unity iPhone editor be vastly different from how they behave in the iPhone build? I could see things running somewhat more slowly on the device, but the difference between needing to tap the screen with UnityRemote and not needing to touch the screen in the iPhone build on the device is pretty strange.

You’re not testing if screen was actually touched. Obviously if no fingers are touching screen result of Input.mousePosition on iPhone is undefined. What is the position of the touch if there is no touch? :slight_smile: You should use Input.GetButton(0) first to check if screen was tapped.

Yes, OnMouseDown is not used on Unity iPhone for performance reasons. Check out http://forum.unity3d.com/viewtopic.php?t=16373&highlight=onmousedown and http://forum.unity3d.com/viewtopic.php?t=15522&highlight=onmousedown for similar discussion.

I added Input.GetButton(0) and it works right on the device now. Thanks for your help.