hi all! I've this problem: I create an assetbundle that contains a single prefab with this code: Code (CSharp): GameObject go = Selection.activeGameObject; string name = go.name; Object prefab = PrefabUtility.CreateEmptyPrefab("Assets/" + name + ".prefab"); PrefabUtility.ReplacePrefab(go, prefab); AssetDatabase.Refresh(); but I've got some scripts attached to the gameobjects inside my prefab but the scripts are not loaded when I load my assetbundle... I assume that are not present in the .prefab... how can I solve this? thanks
I'm not sure if I understand exactly what you're asking, but generally scripts can't be included in assetbundles. Take a look at http://docs.unity3d.com/Manual/scriptsinassetbundles.html
thanks, but the code above is for the 'old' unity 4 system, i'm using the new assetbundle management...and having only a prefab, I think that the problem is when I create the prefab
Hi again, I've reached to load my script in a different way, but after, using the code in the manual, I give this error: the code is this: Code (CSharp): TextAsset txt = codeBundle.LoadAsset(item, typeof(TextAsset)) as TextAsset; var assembly = System.Reflection.Assembly.Load(txt.bytes); thanks again!
The BadImageFormatException would indicate that the txt.bytes doesn't translate to a valid assembly. If you try outputting the txt.bytes to a file, is it identical to the original assembly?
yes, I've added this line: Code (CSharp): File.WriteAllBytes(@"C:\Output.txt", txt.bytes); and the output.txt is the same like the original assembly...
And if you try loading the assembly directly from a file, not through an asset bundle, does it work correctly then? Not sure what could be going on here. You can see the documentation for the BadImageFormatException here: https://msdn.microsoft.com/en-us/library/system.badimageformatexception(v=vs.110).aspx
nope, also reading directly the file, the result is the same: Code (CSharp): var bb = File.ReadAllBytes(@"C:\LayoutTick.cs"); var ass = System.Reflection.Assembly.Load(bb); reading the guide the problem seems to be not in my text file, but for some dll that MonoDevelop uses...
hi @Falcon_DZ , i've created a dll that contains the scripts and after I import the dll.. not yet tested if works right with the latest version