Unity Asset Bundles backward compatibility - c#

I am working in a project, and we use Unity3D ... we are loading our Asset Bundles Dynamically. But we want to add the backward compatibility between the versions of our app.
Let's say that I release version 1.05.0 and the user loaded a certain Asset Bundle, After that the user downloaded version 1.06.0 which contains some changes in some scripts that were used in version 1.05.0
Could I make version 1.06.0 work with the same Asset Bundle of version 1.05.0 ?!
or that is not doable ?!
Thanks in advance

"Some changes in some scripts" is quite vague.
Generally speaking, asset bundles do not include scripts directly, but they do include references to scripts (which may be corrupted if you move your scripts) and to properties (which may get complicated if you refactor). Unity Answers does have some more detailed information.
If all you did was some minor tweak to the Update() function of some script, you should be fine.
If you renamed your scripts or moved scripts between assemblies, you will likely have a problem.
If you create new serialized fields, an older asset bundle will not contain those fields, and they will receive their default value upon instantiation.
If you remove existing serialized fields, they will be ignored upon instantiation.
If you rename or change the type of existing serialized fields, Unity will "try" to reconcile that, but I wouldn't count on it working.
If you're looking for a more robust system, you might be better off attaching "plain old data" components just to serialize your data, then using that data to reconstruct your assets at runtime.

Related

Unity make ScriptableObject on a build

I'm new to scriptable objects, but I've seen a lot of tutorials using them for an inventory system and recipes. My question is if it is possible for a future player of my game to create new "recipes" in the final build that will be saved as scriptable objects. Similar in Minecraft where you can use data packs to create new recipes.
ScriptableObjects aren't really intended to be used that way. They are assets in your build, just like objects saved in your scenes during edit time.
One option could be to try to save them as Addressables or AssetBundles so the game could load them dynamically. I don't think any of those facilities are available at runtime, so you would have to jump through a lot of hoops to get the storage format correct. I'd recommend against that and just use regular object serialization to save stuff.
It's worth noting, when you run your game in the editor and directly update your ScriptableObjects at runtime, it will update the asset and will save with the project. Although it might seem like its working, that only works in the editor. In a real build of your game it will not be saved, and will have it's original values every time you start your game (just like the scene objects all return to their original states).

Recovering inspector values from Unity build

I made the stupid mistake of moving a C# script out of the project and back in. This, of course, cleared all of the important inspector values back to their default values from the script.
All I need is to see those values again and re-enter them. I attempted decompiling the assembly-csharp.dll from my last build using dotPeak. While this did recover the correct classes and their fields, all of the fields are not defined. Where in a Unity build are these values stored, and is it possible to decompile them there?
Thanks in advance!
As far as I know there are stored in the scene file (.unity) or, if it's a prefab, in the prefab file (.prefab) (and if it's a prefab in the scene, it's stored in the prefab file with a list of modifications in the scene file). You might have success finding some values in there, but those are serialized and you can only really read them with Asset Serialization Mode "Force Text". It might also be that they lose their value when you open Unity between moving the script out and moving it back in.
Edit:
I missed the part that you wanted to read them from the build. I don't think that's possible, as they are normally serialized (if they are not in Streaming Assets). As scene files (which I think would contain the data) are also just files and not scripts that get compiled, I think the values are in one of the serialized files.
Also: You don't happen to have any kind of version control? Because then you could rollback to an old commit that contains that data, or if that's not possible look at the specific file in question.

Build an AssetBundle runtime

I'm using Unity and I need a button that calls a function that allows me to build an AssetBundle, so I can make a software external from unity that allows me to build AssetBundle; is it possible?
Thank you all.
Build an AssetBundle runtime
This can not be done. bulding assetbundles requires the buildPipeline which is in the UnityEditor namespace which can not be accessed at runtime as it is editor only.
Making an external application for this that you call from within Unity would most likely also not work unless you know how to replicate their pipeline in your own application, and i doubt you will be able to call it form outside Unity (And even if you could it would still not work at runtime as assets will become read only)
I'm not sure why you would want to build assetbundles at runtime, but the only method i can think of that may work for this would use JSON/XML.
This would need two Instances of unity running to do it in "real time". The first instance of unity would be running your game with the object you want to make into anassetbundle. After clicking your button a function would be called that gets all the information on your GameObject (components, values, ID's, literally everything) and parse it into a XML/JSON file. This file will then be uploaded/saved somewhere where your second Unity instance can access it. The second instance of unity will then read this JSON/XML file in editor time, reconstruct the original GameObject from the data within (This can be done in editor time from script) and then put this reconstructed object through the assetbundle pipeline.
Do take note though that i've never done this myself, and am not 100% it will work. Though i am fairly confident if done correctly it should work.

Can't load Mono.CSharp.dll in either Unity3D or a C# project

I'm working on an online video game project using Unity3D for the clients, and C# servers.
I'm trying to use some code eval for a specific feature, but I can't get it to work.
I went with Mono, because it seemed to be one of the lightest and one of the simplest. I installed Mono and got the "Mono.CSharp.dll" for .Net 4.6 from "Mono\lib\mono\4.6-api". (Both Unity and my servers are configured to use this version of .Net). I dropped it in the Unity assets, and referenced it on my servers.
But I have errors on both Unity and the servers. In Unity there is :
Loading script assembly "Assets/Scripts/Common/References/Mono.CSharp.dll" failed!
And there is an exception on the servers (my IDE is in French so I can't really copy/paste it), but it basically tells me it can't use Reference Assemblies for build, but only for reflection.
To describe the feature I want to create (because you'll maybe have a better solution), I want to be able to create spells from an external tool. Spells are made of SpellEffects. Let's say there is a SpellEffect called DealDamage, constructor takes an int (for the damage amount). I want to be able to write "DealDamage(50)" on my external tool, then take the string, and build a new DealDamage(50) from it.
I know I could find a way to interpret some code by myself, but it would be a lot more work for a far less flexible system.
It was really hard to find any help online for this problem, so as a last hope I'm turning to you.
I'm not exactly sure why you're trying to import Mono into Unity. It's already included in the installation package. If you want to make a modular spell builder, just create a regular application with your preferred language, in your preferred IDE, and save all of your spells as a JSON or XML file, and then import those into Unity. On the Unity side, just build a class to parse the files.
To get you started, take a look at the JSON.Net library. You can serialize your files into C# classes with it.

Unity meta file stored in specific folder

I'm having some problems versioning meta files in Unity. I have common code that I share between my different projects (as git submodules) and they affect some GameObject differently in each projects. Each projects generate different meta files from my common code. That's where the problem is.
If I version the meta files (in my common code), I end up with the same meta files in all my project which is obviously not what I want because the behavior might be different. One of the solutions I found would be to store the meta files related to my common code somewhere in every projects so they stay specific to one project and doesn't affect others. I can't find any information about this.
My question is : is there a way to store meta files in a specific folder and link them to the scripts of another folder?
Yes, you can refer below:
So you treat the different projects as submodules for the common code? If so, you can store meta files to the different projects’ subfolder, and these meta files can be controlled version separately.
Finally, what I did was : I now have a script that copies meta files into my specific project so I can commit them. Then, when you clone the repo, there is another script that copies them back into my submodule. That way, my scene loads correctly. It's not perfect, but it works.

Categories

Resources