hi all!
I’ve this problem: I create an assetbundle that contains a single prefab with this code:
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
1 Like
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
ghiboz
June 11, 2015, 4:00pm
4
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:
BadImageFormatException
System.AppDomain.Load (System.Byte[ ] rawAssembly, System.Byte[ ] rawSymbolStore, System.Security.Policy.Evidence securityEvidence, Boolean refonly) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/AppDomain.cs:788)
System.AppDomain.Load (System.Byte[ ] rawAssembly, System.Byte[ ] rawSymbolStore, System.Security.Policy.Evidence securityEvidence) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/AppDomain.cs:780)
(wrapper remoting-invoke-with-check) System.AppDomain:Load (byte[ ],byte[ ],System.Security.Policy.Evidence)
System.AppDomain.Load (System.Byte[ ] rawAssembly) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/AppDomain.cs:766)
(wrapper remoting-invoke-with-check) System.AppDomain:Load (byte[ ])
System.Reflection.Assembly.Load (System.Byte[ ] rawAssembly) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/Assembly.cs:602)
the code is this:
TextAsset txt = codeBundle.LoadAsset(item, typeof(TextAsset)) as TextAsset;
var assembly = System.Reflection.Assembly.Load(txt.bytes);
thanks again!
steego
June 11, 2015, 7:07pm
5
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?
ghiboz
June 11, 2015, 10:50pm
6
yes, I’ve added this line:
File.WriteAllBytes(@"C:\Output.txt", txt.bytes);
and the output.txt is the same like the original assembly…
steego
June 11, 2015, 11:37pm
7
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: BadImageFormatException Class (System) | Microsoft Learn
ghiboz
June 12, 2015, 6:31am
8
nope, also reading directly the file, the result is the same:
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…
ghiboz
June 12, 2015, 8:45am
9
ok, solved, i loaded directly a c# file, now I created a dll with the .cs and is imported
1 Like
Hi, @ghiboz
i have the same prob, can you plz brief your solution…
ghiboz
August 29, 2016, 12:41pm
11
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