- Home /
Strange hang on load with skybox.
[Wall of text follows. I am going to include as much information as possible in the hopes that some clue will trigger an idea]
We have been having this problem for awhile and I have seen almost no reference to it in other threads/questions.
We first started noticing it when opening the Unity editor and loading a scene with a skybox that uses 4096x4096 textures. The editor hangs with a half-drawn UI for several minutes.
Here are a bunch of data points about this behavior:
*Removing the skybox from the camera, but leaving the material in existance removed the hang
*Adding a cube with the skybox material to the scene in view of the initial camera position removed the hang
*Sometimes texture importing/converting uses multiple cores, but during this hang, one core is maxed out and the rest are minimally utilized.
*The hang happens maximum one time per Unity instance. Once you go through the hang, it won't happen again until you reopen unity.
*With no skybox material assigned, opening the "Select Material" dialog (by clicking the circle-dot button near "Custom Skybox None(Material)" and simply clicking the material causes the hang. This only applies to assigning a material to a skybox, not to other objects.
*When viewing Process Explorer, it seams to be getting handles to files in the Library cache
*Minimal Disk I/O occurs during the hang, but RAM (Private working set) is all over the board, changing by up to +/- 60MB per second.
*It seems to only happen with 4096x4096 imports. 1024x1024 does not behave like this (I don't mean a bit faster... I mean ~1 second vs 3+ minutes). 2048x2048 takes about 10 seconds.
*This only happens in the editor, not in a standalone compile (We aren't doing web or mobile stuff so I don't know how those fair).
*The artist on the project uses an older MacPro (Dual Xeon 2.2Ghz, GeForce 120) and has Photoshop installed. He does not experience this problem.
*My machine is a Core i5-750, GeForce GTX570, 4GB Ram, Crucial m4 SSD 256MB (Unity and the projects are on that, but it happens on my platter drive as well).
*My drivers are up to date. I have also tried this with a Radeon HD4850.
*Also occurs on my Core i7, 6GB, Geforce 560M laptop.
*Problem exists in Unity 3.5 and 3.5.1.
*We are using Unity Free
*Problem exists using Meta files or not.
*The duration of the hang seems to scale with the number of textures.
*Having the game window hidden eliminates the hang until the game window is shown. When the game window is shown, the hang occurs, UNLESS you view the material in the preview pane first.
Here is my best guess of what is going on:
*When the game view window wants to render a 4096x4096 texture in a skybox, it checks some flag in the library cache and decides it needs to reimport all textures.
*When something else (The material preview pane, a mesh with the material applied, etc...) causes the texture to be rendered, it realizes it doesn't need importing and this flag is set.
*From that point forth, the skybox renderer makes appropriate decisions about whether to trigger a reimport.
I could be completely off.
Simple repro:
Create new project. 2. Import a set of skybox textures. 3. Set their import settings to 4096x4096-compressed. 4. Create a new material from these textures, using the skybox shader 5. Make sure the material is NOT selected (and thus being previewed). Select the Main Camera object instead. 6. Close the editor. 7. Open the editor. 8. Add a Skybox component to the Main Camera. 9. Make sure the game view is displayed. 10. Click the circle-dot (what is that anyway?) for the custom skybox field. 11. Select the new skybox material in the "Select Material" dialog. 12. This should hang. If not, try selecting the camera again (after the material was assigned) and reopening the editor.
Thanks very much for slogging through that giant wall of text!
A wall of text is already better than a one-line "its not working" question. Have you submitted a bug report? It seems like this is the kind of thing we can't really help you with...
A good question is: do you really need a 4096x4096 set of textures for a skybox (i.e. 100+ millions of texels)? It looks like a useless overhead.
In the general case 1024x1024 textures for skybox (sometimes 512x512) are enough. I$$anonymous$$HO this hang is just your graphic card telling you that it is full (and fool?).
Answer by rudy.morin · Jun 12, 2012 at 04:51 PM
Hi,
We faced the same issue on Unity 3.5.2f2
After some tests, we managed to find a solution : load everything dynamically... First, you need to put your own skybox shader in the Resource folder...
Example :
// load all skybox textures
Texture2D sbFront = Resources.Load("Texture/Skybox/skybox_Front") as Texture2D;
Texture2D sbBack = Resources.Load("Texture/Skybox/skybox_Back") as Texture2D;
...
// Create new SkyBox material
Material mySkyBoxMat = new Material(Resources.Load("Shaders/myOwnSkyboxShader") as Shader);
// Assign all textures to the material
mySkyBoxMat.SetTexture("_FrontTex", sbFront);
mySkyBoxMat.SetTexture("_BackTex", sbBack);
// Finally set the RenderSettings skybox variable
RenderSettings.skybox = mySkyBoxMat;
Cheers, Spi
Answer by rudy.morin · Jun 12, 2012 at 02:55 PM
Hi,
We faced the same issue on Unity 3.5.2f2
After some tests, we managed to find a workaround : load everything dynamically... First, you need to put your own skybox shader in the Resource folder...
Example :
// load all skybox textures
Texture2D sbFront = Resources.Load("Texture/Skybox/skybox_Front") as Texture2D;
Texture2D sbBack = Resources.Load("Texture/Skybox/skybox_Back") as Texture2D;
...
// Create new SkyBox material
Material mySkyBoxMat = new Material(Resources.Load("Shaders/myOwnSkyboxShader") as Shader);
// Assign all textures to the material
mySkyBoxMat.SetTexture("_FrontTex", sbFront);
mySkyBoxMat.SetTexture("_BackTex", sbBack);
...
// Finally set the RenderSettings skybox variable
RenderSettings.skybox = mySkyBoxMat;
Cheers, Spi