So, in the Unity inspector, when I create the reference between two instances of this ScriptableObject by dragging and dropping, how is that reference created? Is there some sort of ID created in the background of Unity for each ScriptableObject?
I ask because this because of my current link of thinking:
In my custom dialogue editor window, the DialogueElements are stored in a list:
private static List<DialogueElement> dialogues = new List<DialogueElement>();
Here’s a method in that editor for creating a new instance of the DialogueElement (Ignore the random number bit, it’s just to create a unique file name for now):
private static void CreateDialogue()
{
DialogueElement dialogueElement = DialogueElement.CreateInstance(new Rect(correctedMousePos.x, correctedMousePos.y, DialogueElement.minWidth, DialogueElement.minHeight));
//TODO - Come up with a naming convention
var randNum = Random.Range(0f, 100f);
string saveFilePath = dialogueAssetPath + sceneNameText + "/" + randNum + ".asset";
AssetDatabase.CreateAsset(dialogueElement, saveFilePath);
AssetDatabase.SaveAssets();
DialogueElement newAsset = AssetDatabase.LoadAssetAtPath<DialogueElement>(saveFilePath);
dialogues.Add(newAsset);
EditorUtility.SetDirty(window);
}
And then I have a button to call the following method to save the dialogues when I’ve made changes:
private void SaveSceneDialogues()
{
UpdateSceneName();
for (int i = 0; i < dialogues.Count; i++)
{
if (dialogues *!= null)*
{
//Create an asset from the current dialogue
if (!AssetDatabase.Contains(dialogues*))*
AssetDatabase.CreateAsset(dialogues_, dialogueAssetPath + sceneNameText + “/” + dialogues*.windowTitle + “.asset”);
else_
_AssetDatabase.RenameAsset(dialogueAssetPath + sceneNameText + “/” + dialogues.windowTitle + “.asset”,_
_dialogues.windowTitle);
}
}*_
AssetDatabase.SaveAssets();
EditorUtility.SetDirty(window);
}
The connections are created with this method that is in the DialogueElement class when an certain event is called from the custom editor window:
public void SetOutputDialogue(DialogueElement outputDialogue, Vector2 clickPos)
{
if (outputDialogue.windowRect.Contains(clickPos))
{
this.outputDialogue = outputDialogue;
}
}
My current thinking is that these references might not be being serialized between Unity sessions because the links are created between the DialogueElements that are in the dialogues list, and not between the actual asset files that are created, even though the links do appear in the asset files that are created, they just disappear between Unity sessions.
That might be nonsense though, but I’m struggling to find information on this.
I’m including the two classes so that anyone awesome enough to help out can try the editor and see it for themselves. If you include the two scripts in a project, you should be able to recreate the issue, providing that you create the following filepath:
Assets/Resources/Dialogue[76848-files.zip|76848]
Thanks in advance for any help!
Matt