Unity make ScriptableObject on a build - c#

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).

Related

UNITY C# - How can I save a Game Object, that has been instantiated in a runtime, in a runtime?

Ive got a Game Object that I instantiate in a runtime. Then, I make some changes to it like: I add some children objects, components etc.
I would like to somehow save this newly created object for me to use in other scenes and sessions.
Question is: how?
Thank you.
PS obviously I cannot use UnityEditor namespace
If you want to re-use the object in other scenes, you can use DontDestroyOnLoad method to prevent it from getting destroyed upon changing scenes. Afterwards, if you goal is to spawn copies of this object, you can disable it and treat it as a prefab and instantiate copies of it when necessary.
If you want to be able to re-use an object after re-launching the game, you might wanna check out ways of saving data in Unity. One simple way would be using PlayerPrefs but you would have to write the code for loading/saving the state of your object on your own since it's capable of directly saving only int, float, string data type values.
Here are a couple of references:
https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
EDIT:
A more specific solution you can try is serializing a custom class made by you to a JSON file. That class would contain the necessary data to re-create whatever GameObject you had in the scene.
Creating a prefab outside the editor isn't an option. Here's a reference: https://www.reddit.com/r/Unity3D/comments/a5c02u/save_gameobject_as_prefab_at_runtime/

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.

how can i change or add a specific asset in Asset Bundles package,withou send all old asset where i don't want to change(unity)

I apologize in advance for the bad English because I am a French speaker.
I would like help on a problem regarding the creation and management of DLCs with AssetBundles on unity.
Here's what I would like to do:
I create a game with just one scene (Sceneloader) which is responsible for downloading AssetBundles via a defined list and just loading the scenes, it works as follows:
At launch it downloads a list (containing the name of the assetBundles, its hash code, its version, and its download link), it then checks if the assetBundles already exists in memory if it is the case it checks the hash version etc... if they are identical it does nothing, if not it downloads a new version and saves on the disk. If the file does not exist it downloads and saves to disk,
After loading the assetBundles which contains the scenes and the other prefabs and other is instantiated directly to the loading of the scenes which are in the prefabs.
In my list there are currently two assetBundles (one containing the scenes and another containing the prefabs, image, sound etc...)
So what I would like to do:
In the first version of the assetBundles, I would like to send the mainCharacter and two enemies plus some other prefabs in an asset bundles called "MAINASSET", and Two scenes in another asset bundles called "ALLSCENE".
In the second version I would like to send just my mainCharacter (which has been modified) and two scenes (including a new scene and a modified scene2).
All I would like it to be saved on the disk and not just in the cache so that if there is no internet connection we launch the game, or that the items are not downloaded twice. So if there's an internet connection he downloads the list and sees if anything has changed.
If it has changed, it updates the game and saves the update on the disk in this way if there is no internet connection the game can still start being up to date since it is already downloaded the problem is that I don't know how to take to create this second part because I would like the client of the game to have downloaded only the necessary.

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.

Saving Unity mesh created from Tango's Meshbuilder

I want to be able to save the mesh I generate from the Unity mesh builder. From what I can tell the way most people save is with the point cloud data however, I would much rather have the mesh that is generated inside Unity or data so I can recreate the mesh generated in Unity . When I looked into some of the scripts I found a few scripts that seem to deal with the data that is involved with the mesh
CustomPointCloudListener.cs
DynamicMeshCube.cs
DynamicMeshManager.cs
Polygonizer.cs
Voxel.cs
VoxelHashTree.cs
https://github.com/googlesamples/tango-examples-unity/tree/master/UnityExamples/Assets/TangoExamples/ExperimentalMeshBuilder/Scripts
What would be the best way of getting the mesh? I was thinking of trying to save the data by modifying one of the scripts above but I'm not sure where to even start with this.
Edit: the main reason I don't want cloud point data is because I would have to run it through something like this
https://blender.stackexchange.com/questions/7028/wrapping-a-mesh-around-point-cloud-with-cavities
I believe you want to look at the calls into the polygonizer, which is using enhanced marching cubes to extracting the surface. Work back from there to get your mesh (sorry, doing this from memory, don't have the code in front of me)

Categories

Resources