Asset bundles need script references

I have created a simple asset bundle:
http://tagenigma.com/qa/Unity3d/AssetBundleTester/UpdateGUITextPrefab.unity3d

  • Contains a Prefab
  • Contains a GUIText Object
  • Contains a Script attached to the GUIText Object that changes the text of the GUIText Object in the OnEnable event

I have an asset bundle loader test project:
http://tagenigma.com/qa/Unity3d/AssetBundleTester/AssetBundleTester.html

When the asset bundle loads the GUIText does not update.

I have to conclude that scripts don’t actually make it to the asset bundle in any form.

Is this correct?

I found that if I already have “UpdateGUITextScript” script in my project when the asset bundle is loaded, the GUIText’s script will reference the script in my project folder. However, the reference to the GUIText is missing. I think the MonoScripts in the AssetBundles are just references back to your scene and project files. Apparently, you need your source assets and scene that you used to create the asset bundle for the references to work properly.

UnassignedReferenceException: The variable m_guiText of 'UpdateGUITextScript' has not been assigned. This happened in the game object "UpdateGUITextPrefab".
You probably need to select the "UpdateGUITextPrefab" in the hierarchy and assign the m_guiText variable of the UpdateGUITextScript script in the inspector.

UpdateGUITextScript.OnEnable ()   (at Assets\UpdateGUITextScript.cs:11)
UnityEngine.Object:Internal_CloneSingle(Object)
UnityEngine.Object:Internal_CloneSingle(Object)
UnityEngine.Object:Instantiate(Object) (at C:\builds\unity-trunk\unity\Runtime\Export\Generated\BaseClass.cs:59)
AssetBundleDownloader:OnGUI() (at Assets\AssetBundleDownloader.cs:78)
 
(Filename: Assets/UpdateGUITextScript.cs Line: 11)

 Mono: successfully reloaded assembly
Reload assembly time: 0.271655
UnassignedReferenceException: The variable m_guiText of 'UpdateGUITextScript' has not been assigned. This happened in the game object "UpdateGUITextPrefab".
You probably need to select the "UpdateGUITextPrefab" in the hierarchy and assign the m_guiText variable of the UpdateGUITextScript script in the inspector.

UpdateGUITextScript.OnEnable ()   (at Assets\UpdateGUITextScript.cs:11)
UnityEngine.Object:Internal_CloneSingle(Object)
UnityEngine.Object:Internal_CloneSingle(Object)
UnityEngine.Object:Instantiate(Object) (at C:\builds\unity-trunk\unity\Runtime\Export\Generated\BaseClass.cs:59)
AssetBundleDownloader:OnGUI() (at Assets\AssetBundleDownloader.cs:78)
 
(Filename: Assets/UpdateGUITextScript.cs Line: 11)

141728–5183–$updateguitextscript_413.cs (237 Bytes)

Summary: The following video parts show how a script attached to a GUIText object can still function when wrapped in a prefab and then added to an asset bundle as long as you have your original scene and project files. I use a GUIText game object as an example, but ideally any gameObject should work.

Video Part 1 - Create a GUIText GameObject and Attach the update script. Create a prefab assign the GUIText GameObject. And Build an AssetBundle from the prefab.

http://screencast.com/t/vGcIOoln54

Uploaded asset bundle:
http://tagenigma.com/qa/Unity3d/AssetBundleTester/UpdateGUITextPrefab2.unity3d

Video Part 2 - Disable the original GUIText object. Use the assetbundle tester that downloads the asset bundle and instantiates the main asset.

http://screencast.com/t/zdoW35OY

The moral of the story is that as long as you keep your original scene and project files that you used to create the asset bundle, the references should still be correct.

Video Part 3 - Create a new scene and load just the asset bundle. Since the original scene still has the hierarchy the script is able to load

http://screencast.com/t/cNEG9ZXgC2

So I am temped to create a new scene for every exported asset bundle to limit the risk of having a corrupted scene.

Video Part 4 - Building the new scene still maintains the hierarchy and the attached GUIText script executes.

http://screencast.com/t/isnXTglBvqa

Video Part 5 - Given that the script is exported as a package, the package can be imported into another project which allows the script to execute when the asset bundle is loaded.

http://screencast.com/t/wPXrlNe3x

Conclusion: My misunderstanding is that I originally thought an asset bundle contained compiled script. When really an asset bundle just contains a script reference.

142199–5201–$assetbundledownloader_670.cs (3 KB)

Hi there,
Great stuff helped me a lot in my project, but I still have some question. My asset bundles have a hierarchy, the objects are grouped into few groups and I can’t see that hierarchy after uploading. It looks like the script has the references to the geometry and textures but what I want to do is to move them to the scene structure - to hierarchy window - in the same way as when I move the object manually. How can I do that? Thanks

What kind of objects are you working with? Did you try moving your scene objects to a prefab in your project files?

No I use *.fbx files converted to asset bundles.

Can you attach an example FBX that is giving you grief? What software are you using to export the FBX?

There is a simple example of the model I’m using. The problem is that the model is divided into few groups (doors/windows/walls etc) and in every apartment the groups are the same so what I want to do is upload this model as an asset bundle to the scene and after that search for all objects in one of the groups and do sth to all of them.

I tried to attach the fbx file but it doesn’t let me …? Maybe the attached files can only be the txt files…?

You can probably zip and attach.

Point taken.

143936–5243–$apt3_268.zip (310 KB)

Your file isn’t opening buddy…
Can you be kind enough to upload it again for me? :shock: :roll:

this thread is soon half a year old.

congratulations little necromancer :wink:

Hey I still watch my threads. However in the end saving asset bundles to disk was somewhat of a lost cause…

[More Brains]

See, i make the entry to this thread for september. May the thread continues :slight_smile:

i myself have queries relating to the asset bundle, in my posted threads but not adding link here, as don’t want to break the chain.
Or might have broken it. :slight_smile: