Author Topic: Loading GUIs from assetbundles.  (Read 9058 times)

Cwal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Loading GUIs from assetbundles.
« on: September 05, 2013, 03:30:58 PM »
I am using assetbundles to load scenes that contain GUIs, but have run into a major issue.  When they are loaded, nothing displays properly.  It is difficult to explain, so I have included a screenshot of the problem.

I found a post about a similar problem, which was caused by the atlases not being packed in the bundle, but I am unclear how I could accomplish this.  It would appear that the same solution is not providing a fix, as I have added them to the hierarchy and it has not changed the size of the bundle.

When clicking through the instantiated bundle, I can see at least some of the textures, so at least parts are included.
« Last Edit: September 05, 2013, 03:44:45 PM by Cwal »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Loading GUIs from assetbundles.
« Reply #1 on: September 05, 2013, 03:33:20 PM »
Pink generally means that a shader hasn't been compiled properly. Maybe it's not included from the Assetbundle or not in the project?

Cwal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Loading GUIs from assetbundles.
« Reply #2 on: September 05, 2013, 03:58:50 PM »
It does appear to be a shader issue, although I'm not sure what's causing it.  If I open the material in the inspector while in play mode, I can reselect the exact same shader and it fixes all but one text box.
It also throws
"Material doesn't have a texture property '_MainTex'
UnityEditor.DockArea:OnGUI()" four times when the material is clicked on.
It also has a tendency to crash the editor when the shader is selected.
« Last Edit: September 05, 2013, 06:09:00 PM by Cwal »

Cwal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Loading GUIs from assetbundles.
« Reply #3 on: September 09, 2013, 12:06:19 PM »
I'm still trying to fix this.  Removing the shader from the project file has the same results.  Currently a test project is set up to load the assetbundle with the scene immediately, and it crashes the editor when exiting play mode.

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Loading GUIs from assetbundles.
« Reply #4 on: September 10, 2013, 03:03:34 AM »
Yes definitely, looks to me like you aren't adding your textures into the asset bundles. You also have a big hint right here
""Material doesn't have a texture property '_MainTex'"

If you are adding and changing atlas at runtime, Unity won't know it needs to include them inside the asset. You could probably get around the problem by adding objects that use the atlases that you need, unless you are doing that already of course.

Cwal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Loading GUIs from assetbundles.
« Reply #5 on: September 10, 2013, 07:25:11 PM »
It appears that the shader may not be completely included, but I am at a loss for why.  I will cover my attempts thus far.
The material referencing the shader is included in a prefab in the scene that is being loaded.
The texture being loaded exists, as I can see the atlas when I select the material.
If unlit/transparent is removed from the project, it does not reappear when the prefab is loaded, although the material lists it as its current shader.
If the prefab is interacted with, the editor crashes when exiting play mode.  If it is not, it generally pops "Resource file has already been unloaded" before exiting play mode.
At initialization, there is an error about garbage collection that I can't currently reference.

Looking at similar issues, it appears to be a limitation of assetbundles not being able to compile code, but the code needed should already be compiled in the project.
http://imgur.com/3aECicg
Edit: I finally managed to get it to display properly by switching shaders at runtime but it is still crashing the editor on exiting play mode.
It also only displays the text behind the clip panel on Android.
« Last Edit: September 11, 2013, 03:02:19 AM by Cwal »

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: Loading GUIs from assetbundles.
« Reply #6 on: September 16, 2013, 09:18:48 AM »
I have the same issue too. However, if the future uGUI solve this problem, I wouldn't care it now.

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
Re: Loading GUIs from assetbundles.
« Reply #7 on: September 17, 2013, 07:53:33 AM »
It appears that the shader may not be completely included, but I am at a loss for why.  I will cover my attempts thus far.
The material referencing the shader is included in a prefab in the scene that is being loaded.
The texture being loaded exists, as I can see the atlas when I select the material.
If unlit/transparent is removed from the project, it does not reappear when the prefab is loaded, although the material lists it as its current shader.
If the prefab is interacted with, the editor crashes when exiting play mode.  If it is not, it generally pops "Resource file has already been unloaded" before exiting play mode.
At initialization, there is an error about garbage collection that I can't currently reference.

Looking at similar issues, it appears to be a limitation of assetbundles not being able to compile code, but the code needed should already be compiled in the project.
http://imgur.com/3aECicg
Edit: I finally managed to get it to display properly by switching shaders at runtime but it is still crashing the editor on exiting play mode.
It also only displays the text behind the clip panel on Android.

After upgrade, the unity 4.2.1 and ngui 2.7 beginning to appear the same:
Quote
the editor crashes when exiting play mode.  If it is not, it generally pops "Resource file has already been unloaded" before exiting play mode.

I do not know what the reason, but before everything worked fine. Really hate to restart the Unity of constantly Editor crashes.

Cwal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Loading GUIs from assetbundles.
« Reply #8 on: September 17, 2013, 12:11:18 PM »
broken,
If you're doing the same thing I am doing, it appears that most or all of the crashing issue was caused by Unity not handling scenes being loaded through assetbundles and not changed out of before the editor closed.  I fixed it by adding a button to switch back to the original scene.

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
Re: Loading GUIs from assetbundles.
« Reply #9 on: September 18, 2013, 12:22:33 AM »
broken,
If you're doing the same thing I am doing, it appears that most or all of the crashing issue was caused by Unity not handling scenes being loaded through assetbundles and not changed out of before the editor closed.  I fixed it by adding a button to switch back to the original scene.

Of Asset Bundles I loaded
1. scene (LoadLevelAdditiveAsync)
2. models
3. textures (for UITexture)

Yes, if this scene, first go to another scene, and then close the editor, then everything is fine. I do not know what has changed since on Unity3d 4.1.5 and NGUI 2.6.5 it worked fine without falling Editor.

ottolb

  • Guest
Re: Loading GUIs from assetbundles.
« Reply #10 on: September 20, 2013, 01:32:23 PM »
The quick solution I found for this is to change shader when asset bundle is loaded, since it's a tiny file won't be an issue. Although it's really weird error.

In the build version this doesn't happen.
« Last Edit: September 20, 2013, 02:57:47 PM by ottolb »