Question by
ddominnik · Feb 08, 2017 at 09:02 AM ·
c#beginnereventevent-handlingeventlistener
How to call function on AssetDatabase.importPackageCompleted
I'm new to programming with Unity and I'm trying to use the AssetDatabase.importPackageCompleted event to call a calllback function. I can't wrap my head around whats wrong here.
public static void ImportAsset()
{
string assetPath = "Path\\To\\Some\\file.unitypackage";
AssetDatabase.ImportPackage(assetPath, false);
AssetDatabase.importPackageCompleted += new AssetDatabase.ImportPackageCallback(ImportCallback);
}
static void ImportCallback(string packageName)
{
Debug.Log ("This is working" + packageName);
}
Comment
Best Answer
Answer by ddominnik · Feb 08, 2017 at 11:26 AM
For future reference, if anyone runs into the same problem:
public static void ImportAsset()
{
AssetDatabase.importPackageCompleted += ImportCallback;
string assetPath = "Path\\To\\Some\\file.unitypackage";
AssetDatabase.ImportPackage(assetPath, false);
}
static void ImportCallback(string packageName)
{
Debug.Log ("This is working" + packageName);
AssetDatabase.importPackageCompleted -= ImportCallback;
}`