Freezing when see new objects

I have simple scene (one room + player + enemy)
Stats:
Max draw calls = 9
Max Poly = 7k
Max Verts = 4k

Camera don’t see enemy after start… Like in screen

But when i see enemy first time (this is only mesh very simple mesh. Without any scripts) I have huge freeze…
And always have freeze when see new object… This can be simple box and i have freeze… Imo this is something like loading objects to memory, but how resolve problem with this?

Are you getting any error messages? And when you say “freeze”, do you mean the game pauses or locks up completely and has to be freed by force quit?

no no i don’t have any errors…
When I say freeze i mean 0.5 sec lag/spike/freeze → This look like graphic lag on normal games…

This is an issue which needs a solution immediately. I’ve seen it brought up in several threads already.

One pseudo-fix is to instantiate the prefab once bfore it is needed. It must however occur within a camera’s view, but can be hidden behind another object. I’ve found that this does not always work though.

If a true solution is known, it has not been posted, and the ultimate fix would be an actual code change to Unity preventing this issue outright, or providing a “pre-load” feature to overcome it.

The true solution, for any game independent of the platform and engine, is to render it at least once on screen.
The common approach for that is extending the loading screen a little and render it initially right behind the loading screen.
That way the stutter is not visible yet the texture has still been bound and uploaded the graphics memory.

Also ensure to not use max sized textures without compressing them
That might sound nice quality wise but uncompressed 1024x1024 are 6mb of graphics memory (25% of the whole iphone VRAM on pre 3GS) and first need to be read uploaded and read from iphones pretty slow flash memory

I have used that exact technique and not had 100% reliable results.

Regardless, a pre-load function is direly needed as users should not be expected to accept such flawed functionality.

Not that I would not like a magic preloader but in this case I kind of don’t see the reason to wait, because a preloading would do the same thing.

As for the the inconsistent result: did you check your graphics memory use? if you try to preload more than your graphics ram can hold (22mb more or less on pre 3gs), this will naturally happen, because then unneeded areas (textures that are not directly used) naturally are overwritten again for the texture that needs it and need to be cached in later.

If you don’t want to see the issue, use smaller textures, compression and only use mipmap where you know that the texture will not be seen orthogonal in a 1:1 pixel to screen pixel ratio

That beeing said, I have seen and heard that with the 3GS there can be some kind of a hickup, but I’ve not been able to reproduce it on a that drastic level as it it has been told and I can’t really explain it actually (as it happens on the 3GS devices only)

Well, for what it’s worth, when my game level starts up, there are about 120 objects in the scene (using iPhone basic). Any inactive items are loaded, then placed into queues which basically pass them out as needed and return them to their inactive state when they are done. The net result is higher initial RAM utilization with virtually no fluctuation and when the game is started nothing is loaded into RAM at that point.

As for this being a bug in Unity, I am not entirely sure that is the case. Even with the best engines, some things take time. For instance, in Gears of War 2, Epic uses cut scenes to mask loading large levels in the background on the XBox 360. Unreal Engine 3 is a very robust engine and the XBox 360 is much more powerful than an iPhone, yet certain accommodations must be made to compensate for the limitations of the tools and platforms. If we scale this very far down to Unity on the iPhone, developers have to become even more conscientious of how they use resources.

I’m not saying that it’s a “bug”, but there should be a method for dealing with it via a dedicated function in Unity. A mention in the docs would be nice as well.

I suppose that the ideal solution at this point is for the user to construct their own pre-load function which throws up a screen and then instantiates whatever prefabs are needed for the scene at a location appropriate to the camera’s orientation.

I would LOVE to see a “pre-load these objects” function. It would improve the perceived performance of Unity games across the board and save me a ton of headaches! :lol:

The term “flawed functionality” sounds quite similar to a bug, a “lack of functionality” might be more fair, although I would consider this a pretty small matter personally.

Pre-cache assets or demand background loading. Your choice. With more cores in the iphone’s future, hopefully we’ll get access threads soon. Anyone have any experience with GCD or NSOperationQueue that can comment on the viability on Unity iPhone?

Hm, I feel you’re right. Now those who are interested in a dedicated function for this, please conduct a project where we could clearly see the lag and submit it through the bugreporter.

I’ll try to figure out, what exactly we can do about this.
Thanks.

Should be pretty easy to do… a FindObjectOfType(typeof(gameobject)) to get a list of all your objects, then use introspection to find any prefabs within your objects. Once you have a big list of things with textures in them, iterate over that and instantiate them behind a load screen.

Same technique for sounds.

Should be pretty easy to do… a FindObjectOfType(typeof(gameobject)) to get a list of all your objects, then use introspection to find any prefabs within your objects. Once you have a big list of things with textures in them, iterate over that and instantiate them behind a load screen.

Same technique for sounds.

GCD isn’t supported on the iPhone but NSOperationQueue is really, really nice. I use it for any operations that may take some time such as network ops, database hits, post processing images, etc. It is superb and I can’t say enough good things about how easy it is to use.

I´m having this problem with big textures. I have a level with 9 sectors, each sector have 4 textures, 2 alpha and 2 background. When player moves from one texture to other game freezes.

I fix it by adding a loading screen and moving camera trought sector on background to force textures loading.

The problem comes when I change to other sector, then I need to load a full new sector and I cannot put a loading screen again. What can I do to force unity loading all the sector textures.

Wich is the best way to handle 2D scroll textures?

Thanks