Asset bundle is not loaded - c#

I have created asset bundle with this script
using UnityEditor;
public class CreateAssetBundles
{
[MenuItem("Assets/Build AssetBundles")]
static void BuildAllAssetBundles()
{
BuildPipeline.BuildAssetBundles("Assets/AssetBundles/Images", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
}
}
But when I try to open my exe it says
The file can not be loaded because it was created for another build target that is not compatible with this platform.
Please make sure to build AssetBundles using the build target platform that it is used by.
File's Build target is: 9
I also tried
BuildTarget.StandaloneWindows
And it does not work too.
So why it could happen and how to fix it?

Please make sure to build AssetBundles using the build target platform
that it is used by. File's Build target is: 9.
According to Unity's documentation, Build target 9 is for iOS. You are either in iOS mode or BuildTarget.StandaloneWindows64 is not actually building the AssetBundle for WinStandalone. Unfortunately, you mentioned that you switched Platform and the problem but that didn't solve the problem.
Make sure that your Platform is set to Windows Standalone Build.
Go to File -> Build Settings -> select PC,Mac & Linux Standalone then click Switch Platform. Rebuild it again.
Now, replace:
BuildPipeline.BuildAssetBundles("Assets/AssetBundles/Images", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
with
BuildPipeline.BuildAssetBundles("Assets/AssetBundles/Images", BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
Build the AssetBundle again.
Using EditorUserBuildSettings.activeBuildTarget will force Unity to build the AssetBundle with the current active platform.

I download the bundle with
WWW.LoadFromCacheOrDownload(path, 1);
So, as you already understand, it uses the same cache for different platforms, that's why I get iOS bundle for Windows build (because before this I tested it with iOS platform, ahahahah)

Related

Cannot load AssetBundle because "it is not compatible with the newer version of the Unity runtime"

I am trying to load an AssetBundle from a file, however I get the following error:
The AssetBundle 'path\to\file' could not be loaded because it is not compatible with this newer version of the Unity runtime. Rebuild the AssetBundle to fix this error.
I build my AssetBundle as shown on the Unity wiki:
using UnityEditor;
namespace Editor
{
public class CreateAssetBundles
{
[MenuItem("Assets/Build AssetBundles")]
private static void BuildAllAssetBundles()
{
BuildPipeline.BuildAssetBundles("Assets/AssetBundles",
BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
}
}
}
This generates a correct looking AssetBundle, the manifest file also looks fine.
I load the AssetBundle with the following code:
var assetBundle = AssetBundle.LoadFromFile(path);
Both the AssetBundle and the game are built with the same version of Unity, version 2017.3.1f1 (64 bit). I've also tried building both with the latest available beta build, but this did not resolve the issue.
Changing the BuildTarget to BuildTarget.StandaloneWindows64 also does not resolve the issue.
The Unity docs are outdated a bit on AssetBundles, since Unity 2017 they introduced an entire new assetbundle system, which is easier to use and works with an improved UI called the AssetBundle Browser
I've had issues myself when switching from Unity 5.x to 2017.x using assetbundles, and it actually required me to use the new assetbundle system, and build/load through that to get them to work again.
Get the Assetbundle browser:
Download the AssetBundle Browser from Unity's GitHub
Add the downloaded files to your Unity project
Go to Window
AssetBundle browser
Building an assetbundle:
here you will see two tabs, "configure" and "Build". Select the assetbundle you want to build by dragging a prefab of the object into the configure tab. you'll get a question asking if you want to build it as one big bundle or multiple seperate bundles, select whichever you prefer.
The Browser will also give a warning if multiple bundles share the same assets, and propose to make a single seperate bundle containing all shared resource, depending on how many and how big your bundles are this can save quite alot of space.
Then if you go to the "Build tab" you can select for which platform you want to build and the output path, along with some additional options such as compression type. Then all you have to do is click "Build" to build your new assetbundle compatible with unity 2017.x
Loading an Assetbundle:
Loading an assetbundle from a file is as simple as using the following piece of code: AssetBundle myAssetBundle = AssetBundle.LoadFromFile(path);
You can also load assetbundles from Memory (taking in bytes) or load directly from a stream.
An additional bonus to the new AssetBundle browser is that you can customize it however you need All files can be found in /Assets/Editor/AssetBundleBrowser/. for example I included the functionality to automatically upload all bundles to an FTP after its done building.
Edit: The Unity AssetBundle browser tool works for version 5.6 or higher.

Removing ARToolkit nft marker from Android build

when i start the sampleNFT -an already made example from ARToolkit- in unity Editor -pressing play button- it worked greatly
BUT when i build my android app it removes my NFT marker which is in this case "gilbratar"
and i made the player setting and Android manifest as good as it supposed to be !
BTW i'm using Unity 5.3.0f4 and ARToolkit 5.3.1
why i have this problem ?!
check this image for more info
You're posting Unity editor logs, but saying you're building to Android. Do you mean you're trying to hit the "Play" button while your build target is set to Android?
If that is the case, I would recommend continuing on the editor set to your desktop platform for debugging purposes, and only switching over to your build target for building.
Also, make sure that the AndroidManifest.xml in your Assets/Plugins/Android folder has it's package name changed from "com.Artoolkit.demo" to whatever you chose as your Bundle Identifier under build settings for Android.

Unity, Xcode, Compatibility List?

Problem: I am unable build and Run from Unity editor, or attach Monodevelop to a device process.
Specific Versions:
Unity5.2.2f
Xcode 7.1 (7B91b)
I believe this all has to do with compatibility as Unity will spit out the small warning, when you Build and Run from the editor:
Unity xcode plugin has not current Xcode in its compatibility list.
Please launch the project manually
UnityEditor.HostView:OnGUI()
Where can I find said "Xcode compatibility list"?
Workaround for whenever in the future this might happen again:
Open Applications in Finder
right-click XCode app > Show package contents
open Contents
open Info.plist
copy the DVTPluginCompatibilityUUID string
In the Finder window, press ⇧⌘G (Shift+cmd+G)
Enter /Applications/Unity/PlaybackEngines/iOSSupport/Tools/OSX/Unity4XC.xcplugin/Contents
open Info.plist in your favorite text editor
find the part with:
<key\>DVTPlugInCompatibilityUUIDs</key>
<array>
<string>63FC1C47-140D-42B0-BB4D-A10B2D225574</string>
<string>37B30044-3B14-46BA-ABAA-F01000C27B63</string>
<string> etc...
add a line with:
<string>[Paste the copied UUID here]</string>
before this line: </array>
Save the file, and provide your password to overwrite the plist.
You'll be able to have Unity run the build process in XCode again (after restarting XCode)

Cannot load a font on iOS using MonoGame 3

I am trying to load a font into my game for iPhone. I am using C# and MonoTouch and the excellent MonoGame project (I have got the latest build from the develop3d branch on github).
My fonts load correctly on Windows but when I try to run the game on iPhone I get an error saying could not load font. I have loaded the sprite font into a MonoGame content project and compiled for iOS.
I have imported the produced xnb file in as content, set it to content mode in properties and marked it as copy if newer. However it still won't load. After a lot of digging I found that iOS does not support DXT compressed fonts which is apparently what a SpriteFont is.
I have no idea as to how to go about loading the font into my game. Can someone please help with some code as to how to do it?
I have just figured it out. For those who are struggling with the same thing follow these steps:
Create a new solution choose the mono game content for all platforms (which is basically a dummy game for building content)
Add a new mono game content builder project
Set the build type to the type you want e.g. iOS
Add the content you want
In the property window for each content file change the content processor, to the mono game version of the content you are building. e.g. for a texture choose "MonoGame - texture"
Build the solution which will build the content into a folder for the platform you have built for in the release directory
Add the content into your game project from the built folder of the content project. Make sure you set the build action to content and the copy to output directory to copy if newer (or copy always doesnt really matter)
Use the content using the normal content loader in xna

EmguCV 64-bit build runtime error

I am running into issues building an existing 32-bit EmguCV (Version 2.3) into 64-bit using .net 4.0 and VS2010 on a W7/x64 OS. I have purchased a commercial license, if that matters and downloaded from the links provided in the receipt.
The error is
System.TypeInitializationException was unhandled
Message=The type initializer for 'Emgu.CV.CvInvoke' threw an exception.
Source=Emgu.CV
TypeName=Emgu.CV.CvInvoke
I followed the instructions provided in this article. In fact I used the samples projects in the article and they build fine with V2.2, but when I replace with V2.3 binaries (both emgu and opencv), run into the error.
Has anyone successfully built an Emgu (Version 2.3.x) x64 project? Please provide some guidance.
The cause of this error (should anyone else run into the same problem) is that the program cannot access opencv_imgproc231.dll or opencv_core231.dll even though they are present in the output "bin" directory.
There are two solutions:
Add them to the project and set their properties to copy always as they are EMGU's two key files.
If step 1 doesn't work, replace the current key files in the bin folder with new copies.
If both methods fail then there may be a problem with the build, so download a new copy of EMGU from Sourceforge and try again. The error will later be incorporated within an technical article in order to provide a clearer explanation of how to solve it.
Cheers,
Chris
No need to add them to the project; VS will not let you. Simply open FaceRecognizer.cs
at public static partial class CvInvoke and change:
[DllImport(CvInvoke.EXTERN_LIBRARY, CallingConvention = CvInvoke.CvCallingConvention)]
to:
[DllImport(Emgu.CV.CvInvoke.EXTERN_LIBRARY, CallingConvention = Emgu.CV.CvInvoke.CvCallingConvention)]
Ensure you change all of them.
First test this way: open a sample project from emgu cv installaiton directory and run it. for example, open hello world example and try to run it. if sample projects run with out problem then the installation is correct.
For emgu cv sample projects, value of Output Path option in Build settings of the project is set to '..\..\
bin'. To fix your project problem, open the project in visual studio and set value of Output Path option to 'C:\Emgu\emgucv 2.9\bin'. Try to run the project. It must run with success.
Now, set back the value of Output Path option to bin\Debug\. Then, add all DLL files in the 'C:\Emgu\emgucv 2.9\bin' folder to your project using ADD -> Existing Item menu. similarly, add all DLL files in the 'C:\Emgu\emgucv 2.9\bin\x64' folder to your project using ADD -> Existing Item menu. Now, go to properties window and set Copy to Output Directory option of all dll files to Copy Always. Finally, in the Configuration Manager window, create a new configuration for x64 platform.
Good Luck

Categories

Resources