- Home /
Getting Reference to Asset without calling LoadAsset
Our project has 2 classes, CutScene and AnimationCollection, that are saved to disk with the following code snippet:
CutScene cutScene = ScriptableObject.CreateInstance<CutScene>();
// ...set data on cutScene...
AssetDatabase.CreateAsset(cutScene, path);
The CutScene class has a public reference to an AnimationCollection, which is set by someone using the unity editor by dragging an AnimationCollection from the Project area to the field in the inspector when a CutScene is selected.
The problem is that CutScene *.asset files are automatically overwritten as part of a parse process in our pipeline. When this is done, the code checks if there is an AnimationCollection with the same name in the same folder. If there is, then it sets the AnimationCollection field using the following code:
cutScene.AnimationCollection = AssetDatabase.LoadAssetAtPath(path, typeof(AnimationCollection)) as AnimationCollection;
This code works fine, but the act of loading the asset takes some time. As our project has grown bigger, the parse process has started creeping up to 4 minutes in duration, so I am trying to make it run faster. If I have the path to an AnimationCollection's *.asset file, can I somehow use AssetDatabase.AssetPathToGUID to assign the AnimationCollection field without actually loading the AnimationCollection?