Convert .unity scene files to YAML without touching prefabs - unity3d

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.

Related

Are imported model and its prefab coupled?

I import models from Blender into Unity, then make prefabs from them. But can't delete the original imported models without affecting prefabs.
This is the step by step discription:
I create a simple model in Blender. Just meshes, without textures, lights and other things.
Export it as (Collada .dae) - that is not important, which exact format.
Import it into Unity's Project window (drag and drop from file explorer).
Drag it into scene.
Drag it from the scene into Project window - create prefab through "create original prefab" option. Now I have an Unity prefab and original imported file - two "Body" objects for example:
The first "Body" is .dae file, the second one is Unity prefab constructed from it.
As far as I understood, at this point two these objects are tightly coupled. I can't delete .dae file, because all the models from Unity prefab will be deleted too, so I became just an empty object.
Is it just as normal? Have I keep duplicates in the project to use just the Unity's prefab, not original .dae file? Or is there a way to decouple them?
Another example of such a case. He also created prefab from imported model, but at the end he has two same objects in his project: Unity prefab and original imported model.
Yes of course they are!
Your prefab uses the imported model asset(s) as meshes and materials etc.
Is it just as normal?
Yes it is absolutely normal ;)
Prefabs themselves almost don't need any disk memory since they are basically only serialized hierarchy templates and only store serialized values and references. You can open a prefab in a text editor and will see it is jut some serialized YAML text.
It is rather the according imported models and other assets (meshes/materials/textures/etc) these prefabs reference and which are actually storing the "heavy" data.
So deleting the meshes/imported models doesn't make any sense.

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.

Whole level in AssetBundle

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.

Share same Navmesh with Duplicated Scenes

I had a Scene with a map (some buildings and roads) and Baked Navmesh, then I started Duplicating the Same Scene with modifying some objects inside (not the map or the world), so all the Scenes were sharing the same Navmesh somehow, then I deleted the Navmesh accidentally, Now the only way I seem to find is to create a new baked Navmesh for every Scene which will increase the build size too much!, How can I re-share the same baked Navmesh with all Scenes since all have the same map inside ? I am using Latest Unity3D.
Before You Start: if you have a lot of assets in your project changing serialization to Force Text may take a lot of time. So you may want to copy the target scenes to a new project, do the below mentioned steps and paste them back. :)
There is no way to do this from Unity editor, but there is a workaround:
Go to Edit > Project Settings > Editor and change the Asset Serialization to Force Text (default is Mixed) - this makes sure all assets, including your unity scene files are saved as text documents
Now open your scene file (the one with baked NavMesh) in any text editor
CMD+F or CTRL+F to focus on search bar and type "NavMeshSettings". In NavMeshSettings the last entree should be m_NavMeshData:{fileID:1234 //and some more stuff here} - this is reference to your baked NavMesh asset file. Copy the whole line
Now open the second scene that you want to share your NavMesh to (open in text editor again). Find exactly the same line starting with m_NavMeshData, delete it and past the line from the previous scene.
BOOM!
Edit/Tip: You may want to change serialization to Mixed again if you want to. The only downside of texted serialization is bigger files. It is mostly used for version controlling and merging and the scenes and stuff...

apply texture on OBJ files automatically in batchmode

I have created a C# script to create unity3D asset bundles automatically via batch mode. When I import FBX files and export them as asset bundles, on instantiation in the app at runtime the textures of FBX files are applied automatically; if while exporting, textures are in same folder and if the texture filename is not changed. But OBJ files never take the textures automatically. OBJ files are exported and also instantiated at runtime in the app but without textures, with the same batch mode script that I use for FBX.
It is important for my project that textures are automatically applied on OBJ files also. How do I do it?
I am using Unity 4.5.0 on a mac.
Thanks!
Found the solution! Two files are generated when object file is exported from 3D modelling software, one is the .OBJ and other is .MTL. The latter contains texture map information of that particular object file.
If .MTL file is imported along with the .OBJ and textures in the unity project, while exporting asset bundle, unity takes all the textures automatically. When this asset is rendered in the app, all the textures are applied automatically now.