InitializeOnLoadMethod loading assets doesn't load main asset
This is kind of a weird one.
I have an XNode (https://github.com/Siccity/xNode) asset that contains several nodes. These nodes are defined within the project, named Chat
, EventNode
, StartNode
and Prerequisite
, all deriving from DialogBaseNode
. The asset itself is an instance of DialogGraph
which is a child of XNode.NodeGraph
.
Within the XNode library exists a method called OnReloadEditor
, which has the [InitializeOnLoadMethod]
attribute. The problem is contained within this method:
I am looking to obtain all asset paths containing the XNode.NodeGraph
type, using this code:
string[] paths = AssetDatabase.FindAssets("t:" + typeof(XNode.NodeGraph)).Select(guid => AssetDatabase.GUIDToAssetPath(guid)).ToArray();
This code works just fine to obtain the paths of all NodeGraph assets, implying that Unity knows this asset contains a NodeGraph instance, but calling:
XNode.NodeGraph graph = AssetDatabase.LoadAssetAtPath<XNode.NodeGraph>(assetpath);
...yields null when Unity first starts. In fact, even with LoadAllAssetsAtPath
, it loads all internal assets within the file EXCEPT for the NodeGraph instance.
Now, when I recompile the script and run it while Unity is already running (i.e. not starting up), it loads the assets just fine, and I can see the NodeGraph instances flawlessly. The problem exists when Unity is first booting and the method is being called, it seems as if the parent (main) asset is not being deserialized at this point.
Is there anything I can do to ensure that the asset is FULLY deserialized and ready for LoadAssetAtPath?
Things I've tried:
UnityEditor.EditorApplication.delayCall
AssetDatabase.ForceReserializeAssets(paths, ForceReserializeAssetOptions.ReserializeAssetsAndMetadata);
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport)
Any ideas? Thanks!
Your answer
Follow this Question
Related Questions
My scene is empty, and doesn't have any game object but my assets are still here 0 Answers
ParticleSystemMultiplier class missing a reference 2 Answers
Tanks game script SetHealthUI error 1 Answer
Compiler ignores data changes on [Serializable] classes 0 Answers
i want to drag and drop a reference to a component in editor so i can activate and deactivate them? 0 Answers