- Home /
Missing reference to Texture2D after loading prefab from AssetBundle
This problem occurs when loading a prefab dynamically, that was previously exported as an AssetBundle.
Scene setup:
There is one scene containing the instance of a single prefab.
The prefab contains a cube rendered using a material referencing texture A.
The prefab also has a MonoBehaviour attached to it, referencing the same texture A in the inspector.
public class MyScript : MonoBehaviour { public Texture2D A;
void OnGUI()
{
if (a)
GUI.Label(new Rect(0, 0, 50, 50), A);
else
GUI.Label(new Rect(0, 0, 100, 50), "missing reference");
}
}
I export the scene and the AssetBundle as a WebPlayer build, all according to the usual practices. In fact the loading of the prefab and rendering the cube with texture A works fine!
Here comes the problem: The reference of texture A in the MonoBehaviour script is still missing, even though the same asset is used to render the cube inside of the prefab. This means the asset is loaded in memory, but for some reason the inspector reference is broken.
I can provide a simple test scene to replicate this. Sounds like a bug to me, but would appreciate feedback :)
Cheers, Tommy
Your answer
Follow this Question
Related Questions
Sprite in Asset Bundles returned a Texture2D 3 Answers
Object parent Asset Bundle 1 Answer
Replacing all textures in a project? 1 Answer
Load Unity 4.3 Sprites with AssetBundles 5 Answers