Kill application on close

Is there anyway to wipe the game from memory when the user closes the game? I am having many issues with the game when it is closed, and then re-started again (while in memory). The sound stops playing and all kinds of other funky things are occurring. What I want: User presses home button, the game closes and is not running in the background. If the user reloads the game, it goes back to the beginning (splash screen then menu) I would like to disable multitasking on this game. How?

You can add UIApplicationExitsOnSuspend to the Info.plist in Xcode.

Click on the bottom line of Info.plist

Press the “+” symbol on the right to add a new line

Paste UIApplicationExitsOnSuspend into the left field

Right-click on the right field

Choose boolean as the type

Click to get a tick in the box

Thank you so much for this! And for the step by step help!

Interestingly enough, what if I didn’t want it to kill the application on close?

A Unity iPhone 1.7 app on my iPhone 4 used to allow the player to continue where they left off but a Unity iPhone 3.0 app terminates on close for me. :frowning:

Remove the tick from the box in the info.plist file? Although exiting on suspend is not the default behaviour I get from Unity 3 iOS apps … strange!

unity 3 apps are larger on ram, especially if you load textures through WWW / LoadTexture the RAM hunger will be massive.
in this case it can very well happen that iOS kills your application when its in background causae it needs ram for something else.

this is something you will see with iOS 4+ on 3GS, iTouch 4 and iPad which only have limited memory for background keeping with their 256MB of RAM. only the iphone 4 can keep this up longer.

its naturally also possible to eat too much ram without this if your application wasn’t that much optimized …

Thanks guys, good to know.

Is this the reason why with my game, on unity 1.7, it would run fine on a 3g phone, and now that i’ve upgraded to unity 3 with that same game and same 3g phone, and now I can’t get passed the splash screen (it just shuts down)? If so, any suggestions on getting this game to work on a 3g?

its part unity 3 and likely part iOS 4

also you need to check the texture settings as the auto conversion messes them up rather badly

What do you mean by auto conversion? Or do you mean auto compress?

with auto conversion I mean if you convert a unity iphone 1.7 project with unity 3 in which case it will become a U3 project through conversion (its no longer 1.7 nor can it go back any longer). this conversion step trashes th textures import settings rather badly, especially check all gui textures

Ah yes. I’m aware of this. I spent a whole day just fixing my textures. :stuck_out_tongue:

Unity 3 scenes don’t necessarily use more RAM, its just handled differently than it used to be.

I don’t know if its common knowledge, but Unity 3 loads all assets (including referenced prefabs that have yet to be instantiated) at the time of scene loading now, rather than the first time the asset is seen on camera. In 1.7 and prior, you could have a scene with 80mb of textures in it somewhere, but the game would only load them as the textures came into view. This meant your app would start off small and grow over time as the player saw more stuff until it eventually crashed. Unity 3 on the other hand loads everything present in the scene in advance, which eliminates mid-game hitches caused by loading textures for the first time. It also gives you an accurate idea of what your game’s maximum RAM usage is right out of the gate, but it will cause an app that used to skate by on first boot to just crash right away.

The proper way to load things in dynamically is via Resources.Load(). A prefab or texture loaded manually in this fashion will only consume RAM at the time it is used, so you can therefore have a limitless amount of potential content that your scene has access to without Unity needlessly loading it on startup and blowing up your device.