Do I need to include .meta file when build unity assetbundle? - unity3d

In editor, the meta file records reference with other asset, so I think when build assetbundle, I need to include the .meta file also, so at runtime the asset will find the reference with each other.
But according to this link https://answers.unity.com/questions/910422/assetbundleloadmainassetatpath-not-loading-meta-fi.html , the answer said there is no need for it, I'm confused about that

From what I know, Unity uses these .meta files in the editor only. I'm pretty sure that the asset bundle contains data that tells it what files do what. The guy at the link you've posted seems to be pulling .meta files from the asset bundle and I don't think this is the correct way to do this, since you are basically doing it in the reverse of what unity was designed for. Try finding only the assets you are looking for, not the meta files. Also you should not have to manually include .meta files in your asset bundle, unity should do this automatically. And one last thing, Use unity's built in functions for accessing asset bundles rather than System.IO, since the system does not know what an asset bundle is, only unity does. Once the files are extracted onto your drive, then use System.IO on them.
Good luck.

Unity's .meta files contain two important pieces of information:
The GUID that Unity uses to track any references to the Asset.
The settings for the Asset that you see in the Inspector window.
Hence, if you don't include them you risk breaking references and losing Asset settings.
This article on my blog explains meta files and GUIDs in more detail.

Related

How to get a file out of a compiled unity game that I made

I created a mini game using Unity and built it a few months back. It was just a pet project so I deleted the project file but still have the built/compiled game. In the project's ASSETS, I put a text file with some notes that I had created for myself and some scripts.
Is there a way to extract or even just see the text file from my built game? Is there a way to extract all the assets or something?
I'm extremely new at this kind of thing so unfortunately, I don't really know the right way to ask the question or find it on google. Any help would be appreciated.
Thank you.
Probably not
That text file, if it wasn't used as an asset, isn't going to be in your compiled game anyway. But even if it was, finding it and extracting it would be difficult due to the semi-obfuscated nature of dlls and how Unity compresses and builds assets into dlls.
If you want to make the file accessible post-build by design, use StreamingAssets folder.
Otherwise you'll have to rely on 'uglier' methods as mentioned by Draco18s (people steal assets all the time so it's not impossible).
what's your building platform ?
if it's android then you can get a look at the scripts and other text files using ILSpy.
Just change the .apk to .zip
Unzip, and open the compiled files in ILSPY.

How to disable build warnings for specific assets?

When I build/enter play mode in the Unity IDE, many warnings clutter the console window that have been generated by script compilation of 3rd-party assets. How can I disable or hide the console warnings from specific assets without making changes to those assets?
I anticipate people righteously howling about how I need to fix the warnings instead of sweeping them under the rug. But to those folks, please consider...
The code is in 3rd-party assets--not mine. Typically, no upgrade on the asset is available that would fix the messages, and I've reviewed the messages and judged them to be benign. I realize the value of warnings, but I don't want to dig into 3rd-party code to fix the warnings. I'm also reluctant to change the code in these assets because it essentially gives me a local fork. And then future updates on the asset from the 3rd-party will need to be hand-merged against my local updates. That's time-consuming and introduces risk.
Two years later, I can answer my own question. :)
Create .asmdef files such that third party assets are in one manifest, and all project code is in a separate .asmdef. So in my project, I keep the 3rd-party assets just under Assets with project one level down.
Assets (folder)
thirdPartyAssets.asmdef
...other files and folders...
Project (folder)
project.asmdef
...other files and folders
This basically "disables" warnings from 3rd-party assets by simply not building them. You will still see 3rd-party build warnings if those assets change or a clean build is made.
The original question was how to disable for specific assets, so I'll note that it's possible to arrange the .asmdefs to include/exclude assets in different groups. And simply putting an .asmdef into the folder of one asset that warning-spams, will cause that single asset's warnings not to be shown except for the cases I described in the previous paragraph.
Put the plugin into its own folder and make an assembly definition if there isn't one already.
Then you need to create a csc.rsp text file alongside the assembly definition
Edit this csc.rsp and add this line
-warn:0
This will set the warning level to 0 (no warnings) for that assembly only.
see https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/errors-warnings
Thank you to both Erik Hermansen and Adam B for providing solutions.
I went with Erik Hermansen's solution, but modified it slighty, sort of the other way around :) :
moved all third party stuff into a folder Assets/ThirdParty, and created Assets/ThirdParty/ThirdParty.asmdef
kept my own stuff at top level, and created Assets/MyAssembly.asmdef
Note that you probably have to add some references to each assembly:
MyAssembly.asmdef:
ThirdParty.asmf
Unity.TextMeshPro
ThirdParty.asmdef:
Unity.TextMeshPro
(maybe some others, depending on your own project)

A lot of 3D model file can freeze Unity editor and Jetbrains Rider

I would like to use a lot of 3D models more than 4000.
The folder can be at least 20GB size.
When I opened this folder with Unity editor, it freeze my Unity engine and Jetbrains Rider as you thought. However, these models is no reason to be loaded in every time since several models being loaded is determined in dynamic on runtime.
I think I can make use of AssetBundle feature to load these model in dynamic. However, I think that limit assets must be placed in Assets folder to build as asset. That can freeze my editor and Rider.
But technically, I think AssetBundle must be able to be build in separately.
How can I solve this problem?
You can indeed use Assetbundles to fix this issue. If you have all your models build into assetbundles you can store the assetbundle file and assetbundle.manifest on a remote server or FTP and just download it at runtime whenever you need the asset. this way the models will never be in your build project and can even be in a seperate unity project, solving your crashing issues on your main project.
For my answer i'll be assuming you are using Unity's new Assetbundle browser tool and using a Unity version that is higher than 5.6. If you do not have the new Assetbundle browser here are some quick steps to get it:
Download the AssetBundle Browser tool from Unity's GitHub
Add the downloaded files to your Unity project's /Asset/ folder
Go to Window > assetbundle browser
a quick tutorial can be found here
Building the bundles
The benefit of using assetbundles for this is that, as long as the Unity versions match, they can be build from seperate projects. Therefore i would recommend creating a new empty project and testing how many models you can have in that project without crashing Unity.
Once you have found that limit create prefabs out of the models, and add them to the Assetbundle browser tool.
Set the target platform for which you want to build the assetbundles and the compression you want to apply to in the "build" secton of the assetbundle browser tool. once you have done that hit "build" to build your assetbundles.
Once this process is completed you can take the assetbundle file and assetbundle.manifest and upload them to a seperate server or FTP that the client can connect to at runtime to download the required assetbundle, containing the desired model.
Since the new Assetbundle browser tool is open source you can also automate the process of uploading the assetbundles directly after they have been build.
another benefit of this is that the assetbundle browser will detect any shared assets (e.g shaders, scripts) and give you the option you move them into a shared assetbundle that only needs to be downloaded once, and any following assetbundle can call. This way you won't have to keep downloading shared assets.
Building assetbundles is quite a time consuming task (also depending on the target platform and compression settings) so if you have the resources available you might want to do this on multiple computers at once.
You may try to exclude folder from being indexed.
https://youtrack.jetbrains.com/issue/RIDER-8664#comment=27-2399808
I think the best way to fix it is simply not using so many models.
So simple.
You should choose models that will fit best for the rest and just create few diffrent texture for each model.
Its like in the movies. You dont need 2000 ppl to make crowd. You just need 20 different ppl and copy paste there in CGI.

How do I compare local and remote asset bundle versions without actually downloading the asset bundle?

What I'm trying to do
I'm working on a sort of portal to showcase several of the projects my organization has made in Unity. To keep it flexible and light, I've designed an architecture using asset bundles:
When the user downloads the portal, all they download is a bootstrap scene that loads in the main menu scene automatically. This keeps the initial download very light and allows them to get going quicker. Also, having everything else in asset bundles maximizes the amount of 3D content we can update after delivery.
When the main menu downloads and loads, the user is presented with a list of projects. Each project is tied to an asset bundle that can be downloaded on-demand. That way, if they are interested in one project and not another, they don't have to waste time and disk space downloading a project they'd never explore.
If they haven't already downloaded a specific project's asset bundle, they are prompted by a button to download it. If they have an older version, they are prompted to update it. If all up-to-date, they are prompted to visit it.
The Problem
The problem I'm having is two-fold:
I'm unsure what is the best library to use to do what I'm trying to do. Currently, there seem to be two ways of downloading asset bundles WWW.LoadFromCacheOrDownload and UnityWebRequest.GetAssetBundle. Not to mention, Unity just teased ResourceManager and addressable assets at Unite 2017 (but that seems far off).
No matter which library I use, neither seems to have a built-in way of checking a local or remote asset bundle version without downloading the bundle itself.
What I've done so far
In the meantime, I've used UWR to download the remote bundle manifest and Regexed for the CRC and hash. Now looking at Caching.IsVersionCached to Regex the local version and compare, but that method is obsolete...
Any ideas?

Finding assets not in use

Is there a way to know what is of all my GO, textures, sounds, etc, are not in use in all scenes, to delete it?
When i tested my game, I have inserted some textures, sounds, GO etc and some of them are not in use.
I'm using Unity 5.1.1.
2018 ..
The modern solution is simply ..
Click on your scene(s) and select "Select Dependencies".
It will show you what is used; the rest is unused. Really it's that easy.
As with many things in Unity pipeline, it is very common to use an asset, virtually every project uses a few well known assets. "A+ Assets Explorer" (link) is very common.
When Unity builds the executable, it does so only with required assets. Anything else that might exist in your scenes or projects is simply ignored.
This answer over on Unity Answers has more info.
There are also options available in the Asset Store, such as this one.
Asset Hunter is a tool that analyzes your buildlog and gives you an easily understandable overview over unused assets in your project folder.
The results are grouped into folders and file types, making it easy to start cleaning up your project.