Note: Skipping verification/error handling code for clarity. _currentGeneralGameData = Resources.FindObjectsOfTypeAll().FirstOrDefault() _currentGeneralGameData = Resources.Load("GeneralGameData") In your case, this would mean simply grabbing a reference to your existing asset resource, instead of creating a new instance, something along the lines of: When you change it, the changes are "permanent" (saved to that actual object), which I believe is what you're looking for. This is a shared, "actual" object/file that exists in your project Resources. the _currentGeneralGameData = CreateInstance() line in your code) The key difference is how the static value is set. The reason you lose your data is because there are 2 ways people use ScriptableObject for singletons. Keep in mind that when you reference GeneralGameData.CurrentGeneralGameData it is going to create and asset, if you delete that asset you are going to lose you data. _currentGeneralGameData = AssetDatabase.LoadAssetAtPath("Assets/CoreMaker/GeneralGameData.asset") If (!AssetDatabase.IsValidFolder("Assets/CoreMaker"))ĪssetDatabase.CreateFolder("Assets", "CoreMaker") ĪssetDatabase.CreateAsset(_currentGeneralGameData,"Assets/CoreMaker/GeneralGameData.asset") If (AssetDatabase.FindAssets("GeneralGameData", new ).Length != 1) Private static GeneralGameData _currentGeneralGameData public static GeneralGameData CurrentGeneralGameData Public class GeneralGameData : ScriptableObject This is the fixed code based on Nailuj29s answer but you do not need to get reference to it by having a public field, instead you just need to use GeneralGameData.CurrentGeneralGameData. The problem is that it wont save my changes after i hit play or restart unity. = EditorGUILayout.TextField("GameVersion", ) ĮditorUtility.SetDirty(GeneralGameData.CurrentGeneralGameData) = EditorGUILayout.TextField("GameName", ) I also have a window to show and change that public class GeneralGameDataMenuItem : EditorWindow _currentGeneralGameData = CreateInstance() ĭontDestroyOnLoad(_currentGeneralGameData) Public static GeneralGameData CurrentGeneralGameData Private static GeneralGameData _currentGeneralGameData public class GeneralGameData : ScriptableObject I have a singleton class that contains general information about my game.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |