Unity save scriptableobject. Currently i cant save a System.

Unity save scriptableobject SetDirty(obj); is called when you make changes to it. I been able to use the ScriptableObject to save data, during runtime of the game, that is still available after i stop playing the game in the editor. com Unity Engine. Like so many others I have now found that JsonUtility. So I have the following ScriptableObject “Doodad” set up: using UnityEngine; [System. In the former case, does anyone know how I can save the ScriptableObject? In the latter case, does anyone know of a workaround? Further, the ScriptableObject contains two ints for width and height, and a one-dimensional array of a custom enum type (basically a flattened 2d array). . clicking on a button will create a new file in the current selected folder in the project window under the Sep 14, 2022 · 背景:希望运行时可以访问出包参数等出包时注入的信息 核心代码如下 /// <summary> /// 包体相关配置信息,可将出包参数带入该配置并在运行时访问 /// </summary> [CreateAssetMenu(fileName = "BuildConfi Jan 20, 2020 · I’m using a custom editor for a ScriptableObject, and every time I restart Unity, almost all its data is reset (everything except an enum). My current code does not work. value will not be saved inside the ScriptableObject when I Play/Pause the game, but myInt will be Oct 31, 2019 · This seems like a problem that is solved with some minor thing that I just don’t know about yet. I use a ScriptableObject and an intermediate object to encapsulate the array: // Array wrapper [Serializable] public class CityMapArray<T> : IIndexed<T> { [SerializeField] private T[,] _array; public CityMapArray() { _array = new T[1, 1]; } public CityMapArray(int width, int Jul 14, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. The object being inspected: public class GameTagTree : ScriptableObject { [SerializeField] GameTag root = new Mar 30, 2023 · Hey everybody, I’m basically creating some basic voxel-style map editor for myself. But there are also references to AudioClips, GameObjects and Sprites: All those are lost when I’m trying to load them on a Dec 28, 2019 · Hi @fwalker, as this post describes you can read your ScritableObjects. SaveAsset on such objects. asset files. When I change the data inside the scriptable object, events are emmited and those components that have it attached are listening to them and get updated. Any()) return; DialogueContainer dialogueContainer = ScriptableObject. I have one ScriptableObject which manages all of these instances. You can Jul 25, 2013 · I have a ScriptableObject, saved as a . I was able to make codes for the user to choose an image through the directory but I wanted to know if its possible to SAVE the progress the user made? Like if I already imported an image, when I re-open the app again, it should still appear imported to the app. You can Jun 10, 2022 · Im totaly new and playing around with unity and stumbled upon a problem i can’t seem to google my way out of. ToJson" for saving and "JsonUtility. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike Feb 15, 2021 · I have a inventory . SetDirty()”, however I have no idea where exactly to use this, or what to put in the May 4, 2015 · if you modify a prefab’s MonoBehaviour or ScriptableObject variables, you must tell Unity that the value has changed. asset files in my project to define data that doesn’t change. The reason is they are hybrid C# and native engine objects, and when the JSON package calls new to make one, it cannot make the native engine portion of the object. Instead you must first create the MonoBehaviour using AddComponent() on a Nov 6, 2017 · Unity Discussions – 14 Nov 14 Can you use a ScriptableObject to save game state? I have a fairly complex game which involves a lot of ScriptableObject instances at runtime. Nested data type in one Oct 19, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. 编辑模式下的 Feb 1, 2021 · Reading a file. Right now I simply store the data in a three dimensional array of ScriptableObjects of VoxelType which right now has no properties on its own but is inherited by multiple other objects. I was hoping that I could somehow save the game state by just saving this managing object, Feb 20, 2014 · I create an instance of ScriptableObject onto my disk as an . There is no UI to selectively save a ScriptableObject, we can only use Ctrl+S (anywhere) to save but that will also save the scene which is not desired half of the time because there could be temp stuff during editing. I use a ScriptableObject and an intermediate object to encapsulate the array: // Array wrapper [Serializable] public class CityMapArray<T> : IIndexed<T> { [SerializeField] private T[,] _array; public CityMapArray() { _array = new T[1, 1]; } public CityMapArray(int width, int 3 days ago · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. Serializable] public class LDData : ScriptableObject { private string _name; public string Name { get { return _name; } } private int _width, _height; public int Width { get { return _width; } } public int Height { get { return _height Mar 22, 2021 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. Save speed Clean Code Framework architecture Mobile ScriptableObject Scriptable Event Casual ability gameplay UI Jul 13, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. SaveAssets(); After I finished configuring my asset Jul 17, 2024 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. Instead, you need to save them as Assets in your Project. For example: void ReadFile(string directory) { // Getting raw text string text = File. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike Aug 11, 2024 · Hello I’m facing an issue with loading/saving data. The items of the inventory are scriptable object [CreateAssetMenu(menuName = "Item", fileName = "New Item")] public class Item : ScriptableObject { public string itemName; public int itemPrice; public Sprite itemSprite; } This is the inventory script public class GameManager : MonoBehaviour { public static GameManager Aug 29, 2020 · OK, so first you need to create a scriptable object instance with ScriptableObject. Serializable] is the same as to inherit ScriptableObject. In classes that derive from ScriptableSingleton, serializable data you add survives assembly reloading in the Editor. Here’s an example - Let’s say I made a scriptableobject named ‘Item’. Here’s my editor script: using System. Then it will work. When you use the Unity Editor, you can save data to ScriptableObjects while editing and at runtime Apr 13, 2014 · Hi, I have a editor window that stores some scriptableObject, I was able to serize them and store them when i close editor window (OnDestroy), but it wont receive this message when I close whole unity editor, which means i need to manully save them before i close unity. asset file to that slot and I can use its value as soon as I enter play mode and I see changes immediately Aug 12, 2022 · 一个unity有限状态机框架 概述 有限状态机又称有限状态自动机,简称状态机。定义:有限的多个状态在不同条件下相互转换的流程控制系统。状态:物体表现出来的状况,多指行为。比如奔跑,攻击这些都属于状态。条件:状态改变的依据。比如按下攻击键,按下奔跑键。 Nov 30, 2011 · Don’t try to save references to SO’s to a flat file tho (ie: serialize), since Unity doesn’t retain the identifiers between builds. If there was only strings, ints and floats in this Scriptable Object, I’d use "JsonUtility. The more you can change your game at runtime, the more you can find balance and values, and, if you’re able to save your runtime Aug 9, 2011 · Hello, first time poster long time lurker here. CreateInstance(). Search for assets. Any()) return; DialogueContainer dialogueContainer = Jul 13, 2023 · ScriptableObject 是一个可独立于类实例来保存大量数据的数据容器,可以用于在 Editor 会话期间保存和存储数据,或将数据保存为项目中的资源,以便在运行时使用。本文介绍 Jan 1, 2024 · //Serialize and Save MyScriptableObject myObject = ScriptableObject. CreateAsset。 Jun 2, 2022 · 最近在开发的时候遇到的问题:在用ScriptableObject进行保存数据的时候,并不是所有的数据都能正常保存,这让人很是难受。所以我决定系统性地整理一下这个问题: 注:建议大家将自己的Unity文件保存方式设置为Text而不是二进制,这样用记事本打开保存的Assest文件就能明码查看内容。 Oct 19, 2023 · The ScriptableSingleton generic class allows you to create 'Manager' type classes in the Unity Editor. Since different AIs can have different targets I would like to copy the state template, but the documentation doesn’t tell if this CreateInstance creates it only in the memory, or if this gets saved somewhere onto disk. This is useful if your Project has a Prefab that stores unchanging data in attached MonoBehaviour scripts. You can save ScriptableObjects to asset files either from the Editor UI (see CreateAssetMenuAttribute), or by calling AssetDatabase. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike Aug 1, 2015 · Having a bit of difficulty with my modified implementation of Inventory Master from the asset store. When you use the Unity Editor, you can save data to ScriptableObjects while editing and at runtime Nov 5, 2024 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. ReadAllText(directory); // Using a stream reader Oct 10, 2023 · Hello everyone Yes, I know that it is impossible to save Scriptableobject data, but maybe there is someone who still knows how to do it? Let me explain the situation: I have character data recorded in SO. But when I delete the Dec 15, 2016 · I want to use ScriptableObject to save data. You can Jul 21, 2021 · When loading, you can never re-create a MonoBehaviour or ScriptableObject instance directly from JSON. There’s some sort of serialization problem that I just 3 days ago · Thank you for helping us improve the quality of Unity Documentation. Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your Jul 14, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. You can Jul 13, 2023 · ScriptableObject 是一个可独立于类实例来保存大量数据的数据容器。ScriptableObject 的一个主要用例是通过避免重复值来减少项目的内存使用量。如果项目有一个预制件在附加的 MonoBehaviour 脚本中存储不变的数据,这将非常有用。 每次实例化预制件时,都 Feb 15, 2025 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. So, my ScriptableObject IS actually being Aug 9, 2023 · I’m having trouble getting a scriptable object to retain data. SaveState is an Jul 15, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. This class has a List that holds that data. It saves properly when edited through the Oct 19, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. When the game starts im trying to load all the asset files and add them to a list of the same type as the objects. You can Mar 22, 2022 · ScriptableObject 是一个可独立于类实例来保存大量数据的数据容器。ScriptableObject 的一个主要用例是通过避免重复值来减少项目的内存使用量。如果项目有一个预制件在附加的 MonoBehaviour 脚本中存储不变的数据,这将非常有用。 ScriptableObject 这种资源只需设置一次就可以在项目中一直使用。 Dec 25, 2022 · try: {carName. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike 1 day ago · It's used to transform data in xlsx (which defines field name and field type) directly into Unity ScriptableObject asset. Jan 3, 2020 · Is there a way to set one scriptableObject to text? The Project settings are set to mixed format. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike Oct 26, 2014 · I’m not 100% sure what your issue is, but I remember having problems serializing multi-dimensional arrays. Oct 21, 2022 · I’d like to save and load data from Scriptable Object. First I create some assets of a custom class with my editor script and set some variables in the asset that appears in my project folder. I want my ScriptableObjects to have “New Game” (aka “Default”) values, and “Current” values. I just need Jun 2, 2022 · The current editor implementation seems not able to save ScriptableObject without saving the editing scene. asset"); Jun 17, 2021 · hello folks, I’m having trouble saving scriptable objects’ data through an editor script, this is what I’m using to save them atm public override void Oct 26, 2014 · I’m not 100% sure what your issue is, but I remember having problems serializing multi-dimensional arrays. name = aFileName; [BIG CHANGES HERE] var asset = AssetDatabase Jan 28, 2019 · I’ve managed to create an Editor Script to do this, but I need to call it in a non-editor script, which I’m not really certain how to do, if possible at all. It creates spells as . 21: 24534: December 11, 2018 Saving usermade content. The Event has a list of a different, serializable class, EventProperty as a variable. Nov 1, 2024 · Here’s my go-to example of creating (or modifying) a ScriptableObject and telling Unity to save it: github. ToJson doesn’t handle references to ScriptableObjects in a Jul 14, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. Jul 13, 2023 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. I want to do it only via the script and not via the Unity menu. I do feel like that third suggestion of serializing the contents goes against my intention, though - if I were to update the game to fix an issue with an enemy’s stats or something along those lines, their save file would still be storing a redundant copy of the old enemy stats. Hiding the asset only makes sense when using AssetDatabase. public class AnyObject : ScriptableObject { public Texture2D previewTexture; public GameObject prefab; public void SetPreviewTexture() { previewTexture = Nov 14, 2014 · I have a fairly complex game which involves a lot of ScriptableObject instances at runtime. * works. So far I have something that works: // changes PartyMember Lalala = By adding a property before the class name you can create a ScriptableObject from the Unity menu (with a prefab you would just select the prefab and hit Ctrl+D to Mar 7, 2025 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. 2: 966: January 3, 2014 Home ; Categories ; Jul 14, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. public class VoxelType : ScriptableObject { } Jan 11, 2025 · Save data needs to be all entirely plain C# data with no Unity objects in it. CreateInstance<DialogueContainer>(); dialogueContainer. You can Jul 14, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. Collections; using Oct 19, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. select that and a window will open listing all the types of ScriptableObjects in your project that has the [CreateAssetMenu] attribute, as buttons. Unity - Scripting API: EditorUtility. Unity Discussions Save ONE ScriptableObject as text. MonoBehaviour or ScriptableObject don’t do this automatically so if you want your value to be saved you need to call SetDirty. Also, if the class uses the FilePathAttribute, the serializable data persists between sessions of Unity. But I read it was better to use ScriptableObject instead of Enums (especially big ones) to avoid issues related to renaming, reordering etc. This is my current code to save the object every time it is modified. Just like MonoBehaviours, ScriptableObjects derive from the base Unity Object but, unlike Nov 4, 2018 · If have an Event class that is a scriptable object which is saved in the Assets folder. You can convert a byte[,] array into a byte array by using some clever indexing. Instantiate ScriptableObject objects with CreateInstance. Find this utility tool & more on the Unity Asset Store. So is there a way to detect the closing of unity editor? so i can save them automatically. In my editor window script, when the user wants to save the current state of the item manager, I create an asset composed of the item manager (which derives from ScriptableObject) and save in the Resources folder for later use. They have leve Oct 26, 2012 · Hi all: I am having a problem where my scriptableobject doesn’t save setting I input using the editor tool I wrote After tweaking around a bit, I realise if I wrote private Texture myTexture; void setmyTexture(Texture aTexture){ myTexture = aTexture; } it will not save the texture. I am setting some options in the main menu, and I want to use those options in the game. CreateInstance<MyScriptableObject>(); string jsonData = Jul 31, 2017 · I was wondering what the "correct" way to save scriptable objects in Unity that are changed during Play mode. One of them - SaveStateHolder - takes care of data that may break as a result of an update to the game. Essentially I have a custom GraphView editor in which I want the existing scriptable object associated with that graph to constantly update itself instead of requiring manual saving from the user. 使用方法2. Oct 10, 2023 · Hello everyone Yes, I know that it is impossible to save Scriptableobject data, but maybe there is someone who still knows how to do it? Let me explain the situation: I have character data recorded in SO. My problem now though is that I Aug 4, 2023 · My goal is to update a 2D array from an editor script and being able to save it and undo the changes. If you want to save them as JSON there is a forum post that describes well how to achieve that. CreateAsset from a script. All other types work. I currently have scriptable objects that I am using to pass data between scenes. Serializable] public class Doodad : ScriptableObject { public string DoodadTitle; Mar 8, 2023 · So I have a quick question about ScriptableObjects and the need to call functions like AssetDatabase. (!m_Edges. Instantiate ScriptableObject objects with Jun 2, 2022 · 在通过脚本在游戏中或者编辑器状态下对ScriptableObject进行了修改,关闭编辑器后之前的修改又都没了,原因是在修改后要调用下面这个方法才能保存; EditorUtility. The spells that are created mostly store data but also contains some methods for controlling the spells. Or create a single asset bundle which contains every ScriptableObject, and then just don’t unload it till the end of play. For example: // MyClass is inheritant from ScriptableObject base class MyClass example = ScriptableObject. Aug 29, 2017 · Hi everybody. SetDirty(yourObject); on any changes made to it. asset" file float f; } public class DatabaseA: ScriptableObject { public List<ExampleClass> ListExampleClass; }``` Find this utility tool & more on the Unity Asset Store. I’ve been working on an editor tool for my game that allows the creation/modification of items. Type instance. You can Mar 6, 2011 · Ok I try to sum up what my setup is. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike Jun 21, 2021 · When I create the ScriptableObject, OnEnable is called. Not to mention if my ScriptableObject for enemies contains data like the specific Jan 10, 2023 · I’m making a simple app where a user can upload multiple images. The same thing Feb 15, 2010 · Either that, or it might be some bug in Unity. ” So, my ScriptableObject IS actually being Feb 17, 2025 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. You can . Serializable] public class DataUnit { public string UnitName; public QuestionBase[] Questions; } public class Aug 5, 2014 · Looking for a way to have my data stored in a ScriptableObject asset, saved between reloads of unity. Here is my scriptableObject: using System. Sep 6, 2018 · If you have a custom EditorWindow where you are modifying your ScriptableObject you just need to make sure that EditorUtility. SetDirty Feb 18, 2023 · I think about using ScriptableObjects for pluggable AI states as shown in an Unity Tutorial for the tanks-project. SaveAssets(). asset, and I want it to contains an array of generated meshes. Apr 13, 2016 · Hi ! I’m trying to save the hierarchy of mutli scene editing, to be able to load directly the scene setup. One of the main use cases for ScriptableObjects is to reduce your Project’s memory usage by avoiding copies of values. CreateInstance<MyClass>(); // path has to start at "Assets" string path = Jul 17, 2020 · I’ve recently been looking at scriptable objects as a new tool to build my game, and I’ve recreated a set of classes that can hold variables and references for different data types that can be dropped into and shared between objects in my scene as required. The following code: Defines a list item called ScriptableObjectData Defines a data container List<> ScriptableObjectDataManager Creates a Mar 29, 2017 · Hi, Recently I’ve been refactoring some of my ScriptableObject classes and faced some problems. CreateAsset. AddObjectToAsset. Please let me know if you need any further help. Json. You can use the File class to read all lines from the file into a single string, or use the StreamReader to read the file line by line, and perform operations on the line that is currently being read by the stream reader. public class Item : ScriptableObject { public enum Type { Potion, Weapon, Armor } public Type type; public int price; public Vector2 position; public int restore_amount; public int damage; public int Oct 19, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. You can Dec 11, 2019 · Hello Coders I do want to save the preview of a prefab in a Texture2D in a scriptableObject. asset”. asset files in my save data. I read 3 Unity Answers threads, and 2 forum threads, and so far what I know is I have to set the ScriptableObject as dirty using “EditorUtility. To the class DataUnit, whether [System. Here is my ScriptableObject : [System. var filename = ToValidFileName($"{carName}. At this point usually all non serialized data would be lost since Unity destroys the whole appdomain including all objects. Let me explain. I decided to try and mix a little inheritance into the process, and everything went well right up until I noticed that the save data (particularly the list data) doesn’t seem to “stick” after play is pressed or Unity restarted. Now there are two ways to create an Event: Using Right-click → Create or through a script. Serializable] for Foos, changing the values of foos. I was hoping that I could somehow save the game state by just saving this managing object, using BinaryFormatter, but I only get this error: SerializationException: Type UnityEngine. When you use the Unity Editor, you can save data to ScriptableObjects while editing and at runtime Mar 3, 2025 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. I’m not sure where to begin, Aug 1, 2020 · I’ve been more familiar with IMGUI (though I’m still new to the whole Unity things) but I’ve read that when you’re working on a custom editor for a ScriptableObject, you have to manually save properties using the EditorUtility. Aug 15, 2021 · In many talks and presentations, the claim is made that ScriptableObjects save memory over having things saved in prefabs. I’m working on an editor window for creating and managing spells in my game. You can Jun 11, 2016 · Hey I’d like to keep my ScriptableObject only in Scene, not in the Asset Database. Then you can use AssetDatabase to create new assets. 数据复用(多个对象用同一个数据)2. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike Oct 19, 2024 · 使用 ScriptableObjects 以集中方式管理数据,以便从项目中的场景和资源中方便地访问这些数据。使用 CreateInstance 实例化 ScriptableObject 对象。您可以将 ScriptableObjects 保存到资源文件,方法是使用编辑器 UI(请参见 CreateAssetMenuAttribute),或从脚本调用 AssetDatabase. GetSceneManagerSetup to get a list Jan 25, 2021 · I’m trying to make a save system with ScriptableObjects. Sadly, this really cuts the usefulness of SO’s in half, or even less than half. One of the main use cases for ScriptableObjects is to reduce your project’s memory usage by avoiding copies of values. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike Oct 19, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. public class myObject : ScriptableObject { [SerializeField] Mesh[] myMeshes; void Construct ( int count ) { myMeshes = new Mesh[count]; for( int i=0 ; i<count ; i++ ) { myMeshes = new Mesh(); // Filling the mesh with vertices and triangles } } } I want my meshes Apr 11, 2022 · ScriptableObject类型经常用于存储一些unity3d本身不可以打包的一些object,比如字符串,一些类对象等。用这个类型的子类型,则可以用BuildPipeline打包成assetbundle包供后续使用,非常方便。这样除了playerpref和c#文件读取外,另外的一种存取一些数据对象的方法 [csharp] view plaincopyprint? Feb 26, 2025 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. Mar 26, 2018 · I want to save a list of “ClassA” with different typs in the Class “DatabaseA”. You could instead drag into the inspector a ScriptableObject which contains all the references to ScriptableObjects. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. After that, I attach it to field on a component. Not sure this is the source of your problem, so I won’t mark it as an answer, but it’s worth a shot. CreateInstance("MyScriptableObject"); It is possible to give parameters while I’m creating the instance so that the constructor of my ScriptableObject class can initialise the instance using those particular parameters? At the moment, I’m having to make do with Aug 24, 2022 · While I never really wanted a ready-to-use save and load solution from Unity like most other major engines may have, I prefer some simple basic features where we can build on top our own solutions. [CreateAssetMenu] public class IntVariable : Apr 8, 2020 · I’m attempting to save a ScriptableObject generated in an editor script in Unity, but it doesn’t seem to be saving the data properly. Everytime you ScriptableObject is a serializable Unity class that allows you to store large quantities of shared data independent from script instances. During the game session, I noticed that I can change the data, but when Jul 16, 2023 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. Unity will save it when you select File > Save Project. I have a problem where a ScriptableObject doesn't save its members properly when edited through a custom EditorWindow. A quote from the Serialization blog entry: “Asset types (Materials / Meshes / AnimationClip / SerializedObject’s) that are created from code are saved in the scene so long as a game object or their components in the scene references it. * This works flawlessly. . CreateInstance<Quest>(); AssetDatabase. However if change the variable from private to public . asset"); AssetDatabase. public class DataGroup : ScriptableObject { public string GroupName; public DataUnit[] Units; } [System. type: The type of the ScriptableObject to create, as a System. object obj, <-- will not be saved in the ". So far I have something that works: // changes PartyMember Lalala = Aug 14, 2019 · 最近在开发的时候遇到的问题:在用ScriptableObject进行保存数据的时候,并不是所有的数据都能正常保存,这让人很是难受。 所以我决定系统性地整理一下这个问题: 注:建议大家将自己的 Unity 文件保存方式设置为Text Aug 14, 2019 · Unity中使用ScriptableObject存储数据一、ScriptableObject简介二级目录三级目录二、ScriptableObject的使用1. Unity Engine. Not sure this is the source of your problem, so I Feb 20, 2020 · Technically it is true that when entering playmode Unity does perform an assembly reload. I also have another scriptable object for the window to remember which window was selected Dec 19, 2015 · 文章浏览阅读1. A quote from the Serialization blog entry: Asset types (Materials / Meshes / AnimationClip / SerializedObject’s) that are created from code are saved in the scene so long as a game object or their components in the scene references it. Since you’re using a different method to draw your UIElements, Jul 16, 2023 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. When I click a button, I want to pass a parameter to an editor function which will create a new scriptable object and save it to the desired location. Using right click works fine and it saves the EventProperties correctly. However I want to include a save/load System with it. To my (limited) thinking, this would mean Feb 21, 2025 · I’m currently trying to save changes made to a scriptable object without the references becoming stale once I’ve made the changes. Use the Soap - ScriptableObject Architecture Pattern from Obvious Game on your next project. 配置文件(配置游戏中的数据)3. SetDirty Feb 21, 2025 · Here is the code I’m using to save the object: public void SaveGraph(string aFileName, string aPath) if (!m_Edges. Like if the spell contains a Projectile component the Mar 18, 2024 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. Mar 6, 2025 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. A great enhancement to Unity would be to reserve the internal identifiers for SO’s so you can simply serialize references to Feb 14, 2019 · Really going to town on option 3. However, if I use the script, it seems to Feb 8, 2017 · To create a new instance a new menu item will appear at the top in “Tools>Create New ScriptableObject Asset”. To keep track of player progression through my game, I created a Dictionary<EventFlags, bool> and I saved that using Newtonsoft. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike Dec 8, 2023 · ScriptableObject是什么ScriptableObject是Unity提供的一个数据配置存储基类它是一个可以用来保存大量数据的数据容器就像是可以自定义的数据资源文件它是一个类似MonoBehavior的基类需要我们继承它来进行使用它的主要作用是1. Instead of referencing a MonoBehaviour singleton. Jan 20, 2025 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. Unity builtin components internally call SetDirty whenever a property changes. Jun 11, 2016 · Hey I’d like to keep my ScriptableObject only in Scene, not in the Asset Database. The type of the ScriptableObject to create, as the name of the type. 3w次,点赞5次,收藏13次。Unity - 序列化 ScriptableObject、SerializedProperty 编辑器运用结合编辑器类使用序列化, 将数据显示在 Inspector 面板,并且执行序列化保存数据。如图 上图为将自定义类 Jul 26, 2024 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. I have created a bunch of scriptable objects to hold information of different items. Using ScriptableObjects makes it easier to manage changes and debugging. If you want to save a ScriptableObject asset then you will need to save it as a standalone asset using AssetDatabase. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike Nov 2, 2023 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. This question has been asked many times in many forums and Unity answers. The reason is they are hybrid C# and native engine objects, and when the JSON package calls new to make one, it cannot make the native engine portion of the object, so you end up with a defective “dead” Unity object. CreateInstance<CubeScriptableObject>(); 在游戏开发过程中,我们会经常与数据打交道。很多时候,我们会为游戏对象配置数据,比如玩家初始生命值、技能伤害等。那么就需要有个能够存储数据的东西来和游戏对象进行交互。 假设现在要做一个“打飞机”的游戏,玩家操控的飞机在吃了不同道具后会发射不同类型的子弹,这些子弹的飞行速度和伤害各不相同。那么显然我要为每一种子弹配置好它的属性值。 实现方式有很多 Mar 7, 2025 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. But if i fully close and restart unity, the data is reverted to the last values entered via hte inspector. You can Aug 10, 2010 · Here is a link to a mega thread by a unity Dev about scriptableObjects best practices. FromJsonOverwrite" for loading*. I have tried all the usual things (below) but nothing seems to work. Can someone experienced assist ? Many thanks. Just like MonoBehaviours, ScriptableObjects derive from the base Unity object but, unlike Sep 8, 2021 · Let’s say I create an instance of this ScriptableObject public class MyObject : ScriptableObject { public int myInt; public Foos foos; [System. You can save ScriptableObjects to asset files either from the Editor UI (see CreateAssetMenuAttribute), or by calling AssetDatabase. SetDirty() as well as doing AssetDatabase. Nov 29, 2024 · Thank you. If you are just using the default inspector Jun 18, 2021 · 通过代码获取ScriptableObject文件时,就通过加载文件的方式,通过路径加载: 通过代码保存ScritableObject的方式: CubeScriptableObject cubeAsset = ScriptableObject. Mar 20, 2016 · Hi, I’m currently stuck with a nullreference issu when I’m trying to acces a bool[,] from an asset. However when an assembly reload happens Unity does actually save and restore even private fields it can serialize. I am currently achieving this by creating the Jan 14, 2025 · How do I save changes to a custom window? I want to create a window with 3 or more tabs and I want the window to remember the changes I make. also you could try to clean the filename first like. I am also using ScriptableObject classes saved as . Serializable] public struct Foos { public int value; } } If I don’t put [System. Yet, so far as I can tell, for a prefab instance to then ingest and locally use the values or properties of a prefab, it must have variables/properties it can set to the values stored in the ScriptableObject. Most ready-to-use solutions have limitations or specific game types in mind (games like the old halflife actually store the whole bsp map with all Jan 20, 2024 · 在Unity中, ScriptableObject. but all the tutorials online are talking about editor scripting! ☹ I know I need to use CreateInstance to constuct my object, but if I use the technique from the live training video linked above, will Jul 31, 2017 · Unity Discussions – 15 Feb 10 Why doesn't my ScriptableObject save using a custom EditorWindow? Solution Call EditorUtility. But without ctrl+s, merely editing the Oct 19, 2023 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. Then I planned to use that file at runtime so I create a public variable in one of my component as that ScriptableObject type so the slot would show up in the inspector. Aug 4, 2023 · My goal is to update a 2D array from an editor script and being able to save it and undo the changes. legacy-topics. 使用 Jul 31, 2017 · I was wondering what the "correct" way to save scriptable objects in Unity that are changed during Play mode. Collections; using Nov 17, 2017 · In my game save system I am using plain C# classes to hold the data. asset file. ScriptableObject in Apr 17, 2020 · Hi, I am having some trouble understanding how saving using Undo. julian_cruz January 3, 2020, May 21, 2022 · - StarManta on the Unity3D forum boards Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work. It's aimed at convenience in xlsx sheet output and fast retrieving sheet data at runtime. Events in my component are called when it is attached via a custom editor I created for it. Note you only need to do the conversion prior to serialization, if refactoring would Nov 13, 2019 · The issue is that if you take one of those scene objects and make a prefab out of it, and then instantiate that prefab using addressables, it seems the reference in the instance points to a new copy of the ScriptableObject - not the common one shared with the rest of the app. You can Apr 18, 2023 · ScriptableObject: 最常用的功能就是背包系统的实现,ScriptableObject的特点是在游戏结束后,数据不会清除,依旧会保留游戏中产生的数据。所以可以利用这一点来做背包系统 什么是ScriptableObject: 查阅Unity官方手册解释成为ScriptableObject是一个数据容器,可用于保存大量数据,而与类实例无关。 Aug 31, 2012 · The only way to create an instance of a ScriptableObject seems to be: ScriptableObject. asset Mar 31, 2024 · ScriptableObject是什么ScriptableObject是Unity提供的一个数据配置存储基类它是一个可以用来保存大量数据的数据容器就像是可以自定义的数据资源文件它是一个类似MonoBehavior的基类需要我们继承它来进行使用它的主要作用是1. I’ll talk about ScriptableObject singletons, a super cool pattern to avoid prefabs in the scene just to store resources to spawn or game settings, Sep 18, 2015 · I’m been starting to work with ScriptableObjects recently and are loving the functionality so far. 数据复用(多个对象用同一个 Oct 22, 2022 · I have a scriptable object that doesnt seem to “remember” things between play sessions, at least nothing more complex than an int. CreateAsset(quest, "Assets/New Quest. ScriptableObjects derive from the base Unity object but, unlike MonoBehaviours, you can not attach a ScriptableObject to a GameObject. You can Nov 1, 2024 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. object in my list. At the moment I am creating a ScriptableObject for each tab to store data and a custom editor for each to display as I want. In some places I need to refer to these . I have verified that the data is assigned properly and is not null while still in the script, and generating the ScriptableObject at runtime and using that works as intended. It gets the preview, but it is not able to save it in the sriptableObject. I then drag my . CreateInstance() 是一个用于创建ScriptableObject实例的方法。ScriptableObject是一种特殊的Unity类,它可以用于创建自定义的可序列化数据对象,可以在项目中用于存储配置、数据、状态等信息。 Sep 10, 2017 · Hi, I’m struggling to perform a simple task: save List data to asset in the custom editor code. However, when I attempt to use the saved ScriptableObject, all of the data Aug 19, 2023 · I’m developing an EditorWindow that dynamically creates scenes and saves them in the asset folder and add it to the list, this part of the save works perfectly including saving the name of the scenes in this ScriptableObject file. Now, I’m aware that if I alter a scriptable object at runtime whilst I run it in the editor, it will actually save into the . When you use the Unity Editor, you can save data to ScriptableObjects while editing and at runtime Feb 22, 2025 · A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. { int i; System. asset as YAML format in any Text Edit software such as Sublime, Visual Studio or XCode. Currently it resets on each domain reload (every time I change some code in my project and every editor restart). Feb 8, 2015 · According to the live training video, ScritableObjects are serialized using Unity’s serilization techniques, and are better for saving dynamic lists etc (c# serialization cant do them). Anyway, I have a solution to suggest for this “problem” and a question about a strange behaviour in the editor. Currently i cant save a System. public class WorldData : ScriptableObject { public Dictionary<string, Region> regions; [SerializeField] public int worldWidth = 40; [SerializeField] public int worldHeight = 20; public GridSpot homeGrid; public void Nov 18, 2024 · Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project. I tried the way described on the Multi Scene Editing page on Unity doc which says : "To avoid having to set up your hierarchy every time you restart unity or to make it easy to store different setups you can use EditorSceneManager. I have the class SaveData, which inherits from ScriptableObject, that holds several other classes meant to hold different kinds of data. They have leveling variables, current weapons, and other changeable data. Everytime you Apr 14, 2016 · Take a look at the docs, it suggests the correct way to modify/save properties using a SerializedObject. Quest quest = ScriptableObject. Trim()} as it looks like there is a whitespace in front on “. 示例演示 一、ScriptableObject简介 二级目录 三级目录 二、ScriptableObject的使用 1. Questions & Answers. rfwum amo eai mrxo eurb wom nlv nyqgd qqmwjf bwvmrj uqsix yxmh nko zgtdas pfjetn