Whole level in AssetBundle - unity3d

I am building a simple 3D game and I am trying to make it as small as possible.
Currently I loading most of the 3D models (like characters) from an AssetBundle that I have created.
The problem is when I try to compress a scene (with its baked data, like occlusion culling) to AssetBundle I get the following error: "Cannot mark assets and scenes in one AssetBundle".
How can I do it?
currently for compressing the models I am using the BuildPipeLine and the AssetBundleBuild classes.
I have found that link but it didn't help.
Also found the function BuildPipeLine.BuildStreamedSceneAssetBundle but it is deprecated…

As the error states "Cannot mark assets and scenes in one AssetBundle" you can not build your scenes and assets into one assetbundle by design. The two assetbundles are also inherently different from each other, preventing you from building a single assetbundle containing both a scene and assets (like 3d models).
What you want to do is create a seperate assetbundle containing your scene, and creating a seperate assetbundle containing your 3D models that is dependant on the scene assetbundle, and loaded in after the scene assetbundle is loaded.
On a side note it seems like you are still using the old AssetBundle pipeline. Unity has release a Unity plugin tool for the new assetbundle workflow, including a better build pipeline, and a nice UI for managing and inspecting assetbundles called the Assetbundle Browser Tool.
Using this tool you can easily make out which of your assets are giving issues and shows which bundles are scene bundles and which are asset bundles through icons (Scene assets show a little unity logo with black, assetbundles are blue).
It also has its own small debugger which will show any additional errors that will be caused by building said bundle. Making the entire workflow and debugging process alot smoother.

Related

How can I pack files inside Assets in Unity to reduce the quantity?

I work with unity game projects with thousands of models and other resources inside the Assets folder. After a while, this becomes too slow and inconvenient, due to the constant refresh and meta files. Most of these files do not change constantly, so we can consider them static. Deactivating auto-refresh is ok, but there are still too many files.
Is there a way to pack a bunch of files so Unity only handles one file for all of them inside the Assets folder? I know there are packages, and budles, but to use them in the editor, you have to unpack them. Therefore, packages and budles wont' help me.
Thank you.
According to your situation, you can first try organising them in different sub-folders. If one folder contains too many objects, it will cause lag for sure.
Instead of having thousands of prefab objects, you can also try export those 3D per scene as fbx in unity. Then, import this fbx as single file.
By doing this, your scene become single fbx instead.
For level or scene design, we used to combine everything or pack everything into one fbx object as possible. only keeping the necessary props as individual prefab.
ideally, you should also optimise the packed fbx in other 3D software. for example, removing duplicated faces, invisible faces..etc This workflow can cleanup the whole scene, and run smoother in low-end device or VR mobile headsets too.

Convert .unity scene files to YAML without touching prefabs

Is there any utility out there that will convert a .unity scene file to YAML without affecting the rest of the prefabs and assets? I've found instructions to change the Asset Serialization in the editor, but it affects all assets, where I would like to only do our scene files. (Our project has a large number of files and converting them all is too much risk at this point in the project.)
For as far as I know, there is no selective serialization option. If you serialize to text (YAML in this case), that will happen for all of Unity's internal asset types (scenes, prefabs, scriptable objects, etc.). Of course this does not apply to any of the external assets.
Make a copy of your project, switch serialization to text. Copy the reserialized yaml scene file back into your main project, where you set the serialization to mixed.

How to recognize a multiple Vuforia AR targets in Unity without creating a separate object for each?

I'm trying to do a simple AR app using Unity and Vuforia.
I have a large number of AR targets in the Vuforia database, and my goal is that each of them be recognized by the AR camera and the target name was displayed on the screen (to understand which one was recognized).
I'm new to development in Unity, so now I've made only an application in which all the targets are located in one scene as ImageTargets and on top of them are the objects that are displayed when recognised. I want to increase the number of targets, but creating separate objects for all of them inside the scene looks wrong.
Is there a way to add a large number of targets to the scene without creating them all manually?
I think one game object per image target is the right way to do it. If you don't want to start with lots of complex objects in the scene, you can instantiate the targets' content dynamically using prefabs and tracking events instead of objects on top of them.
More details here: https://library.vuforia.com/articles/Solution/Working-with-Vuforia-and-Unity.html

Is there a way to build asset bundle that exclude texture2d from an image?

In unity 4.x, I can archive this because I can select my resource type directly as Sprite variable before putting it into the bundle via BuildAssetBundle. However, in Unity 5.x, I need to put the name in the Editor can I cannot choose my resource type as Sprite only in the Editor. When I make the bundle, bundle will have both Texture2D and Sprite which I only want Sprite to save the memory and disk space. The bundle will exclude Texture2D only if I create the bundle from Prefab not the image itself but I want only the raw image. What should I do?
As clarification for future readers, I'm taking into account your other question, and that the reason you want to exclude the original texture is because you use the atlas that the Sprite Packer generates.
Short answer: Just don't add the textures in any bundle and let everything be taken care of in the shadows. For each bundle, any sprite or atlas needed will be referenced by the object that needs it, so they will be included.
Long, but insightful answer: First, let's compare the two AssetBundle buidling pipelines:
In Unity 4.X, to create an AssetBundle you chose the assets you wanted to bundle together. You would then call BuildPipeline.BuildAssetBundle, using the BuildAssetBundleOptions to optionally CollectDependencies or include the CompleteAssets.
In Unity 5.X, the old system is flagged as obsolete but still supported, though according to this post it might not be in the future. Adding to that, the new system will be further developed, so using the old one should be avoided.
The new pipeline is now integrated into the AssetImporter. Now, when building a bundle, the behaviour is that of having both CollectDependencies and CompleteAssets enabled in the old method.
Sprites are generated by the texture's import settings, and don't have any AssetImporter of their own. The texture atlases created by the Sprite Packer are cached in \Library\AtlasCache, so they don't have AssetImporters either.
This means that individual sprites and packed atlases can only be included in a bundle when they are dependencies of another included asset. As said by someone working on it.
If you add a texture to a pack, all the sprites it created will be added (this is the CompleteAssets behaviour), but of course this will add the texture itself too.
If a sprite is added, the texture it uses will be added too (CollectDependencies behaviour), regardless of if it's a texture file in the project or a Sprite Packer atlas.
The bottom line is that you don't want to add the texture. At all. Never. The original textures are for editor work only. Instead, you need to do add to the bundle anything else that references the sprites, but not the texture itself.
The hackiest way to do that is using a prefab with a script like this:
public class SpriteReferences : UnityEngine.MonoBehaviour {
public UnityEngine.Sprite[] sprites;
}
But chances are that among all the things you want to add to the bundle (prefabs, scenes, scriptableObjects) the sprites you need are already referenced, so they will be added, and in turn any needed atlas will be added too. And everything done without adding the original texture.
Beware: If a single object in an asset bundle references a sprite, its whole atlas will be added. Keep your packing tags organized, they should roughly correspond to the bundles you make.
This issue has been fixed by Unity in Patch 5.1.2p1. You don't need to do anything fancy at all. Unity will do it all for you. Just follow the simple build asset bundle step and that's it. :)

Unity 3D importing

I used to code in c# using Xna then I saw Unity 3D engine and I downloaded latest version installed correctly started development of my game but suddenly when I was importing my animated character Unity 3d blocked my pc ! I noticed that my keyboard goes off when that happened and I cant move arrow or call task menager I can only restart pc ! So brother and sisters help me on my way .
Model files that are placed in the Assets folder in your Unity project are automatically imported and stored as Unity assets.
A model file may contain a 3D model, such as a character, a building, or a piece of furniture. The model is imported as multiple assets. In the Project view the main imported object is a Model Prefab. Usually there are also up to several Mesh objects that are referenced by the Model Prefab.
A model file may also contain animation data which can be used to animate this model or other models. The animation data is imported as one or more Animation Clips.
What I understand in your question is that whenever you try to import assets into unity it makes trouble.
Try to place them in the folder in your drive and then run the project in Unity.
The normal path of Unity project is C:\Users\Public\Documents\Unity Projects
From what I understand; Your computer is spazzing out when you're trying to import Animated 3D characters into Unity 3D
I have faced a similar problem.
The solution I believe might work is :
Create the appropriate folders inside of unity. Assets > Models
Outside of unity, place the OBJ file for the models into your c:\Users\Public\Documents\Unity Projects\Your Project or wherever it might be, in the Assets\Models folder.
Then when you're inside unity, it should be in there without any issues.
That should do the trick.