Hi there Uniteers. I am currently developing a hierarchy creation system in an editor window, and I have trouble serializing my newly created data, as it simple gets destroyed upon play/exit in the editor.
What the tool can do is create a hiearchy tree of custom classes:
- Quest Manager
-
- Quest
-
-
- SubQuest
-
-
-
-
- ObjectiveInSubQuest
-
-
Each of these classes inherit from a class called “HiearchyEntry”, in which is a List that contains all the objects of the “sub” class. So basically, QuestManager have a list of Quest. Each Quest have a list of SubQuests etc…
The HiearchyEntry contains information about the quantity of sub-types and index values while the child class have some custom logic for game purposes.
The scripts I use are:
Base class: - Contains List<object> where Object is the sub element in the hiearchy
[System.Serializable]
public class HiearchyEntry : ScriptableObject
{
[SerializeField]
List<Object> listOfEntries = new List<Object>();
}
###Child class: - Inherits from HiearchyEntry, and contain custom code for game logic
[System.Serializable]
public class QManager : HiearchyEntry
{
public void GetAllActiveQuests()
{
// Insert game logic
}
}
###Editor script: - Get the reference of QManager from Manager and feed the information to the editor window
[CustomEditor(typeof(Manager))]
public class QManagerEditor : Editor
{
public override void OnInspectorGUI()
{
if (GUILayout.Button("Open Quest Manager"))
{
Manager ManagerMonobehaviour = (Manager)target;
if (ManagerMonobehaviour.qmanager == null) // Creates a new instance of QManager if it doesn't exist
ManagerMonobehaviour.qmanager = (QManager)ScriptableObject.CreateInstance(typeof(QManager));
QManagerWindow newlyCreatedWindow = (QManagerWindow)EditorWindow.GetWindow(typeof(QManagerWindow)); // Opens the editor window
newlyCreatedWindow.InitializeWindow(ManagerMonobehaviour.qmanager); // Initiliaze the new window with the QManager.
}
}
}
The creation of the hiearchy is functioning as intended, but whenever I enter/exit playmode, all my hiearchy data is lost and you will have to create the hiearchy from scratch.
I have looked through various posts and blogs about serialization etc, but nothing have worked out, I am not even sure what I am trying to do is possible.
I have alot of code, and so I have tried to minimize it to, what I believe, is the error. Pleas ask for more information if you think I have left something out.